rs.GetPoints() - base_point argument not hooked up?

I was playing around with something and I stumbled on this… I looked at the code for rs.GetPoints() and although the method’s input arguments do include an optional argument base_point (starting point), it doesn’t appear to be hooked up to anything else in the code. Seems odd that nobody has discovered this yet?

Here is an image of the full rs.GetPoints() code in the editor, if I highlight the base_point argument, you can see that the only other thing that gets highlighted is in the initial comment section:

Just to confirm my finding after inspecting the code, I tested with this:

import rhinoscriptsyntax as rs
import Rhino

start_pt=Rhino.Geometry.Point3d(0,0,0)
pts=rs.GetPoints(True,base_point=start_pt)

If you run that, you can see that the first point pick can be anywhere, not just constrained to 0.

While I’m here, I made the following request concerning rs.GetPoints() about a year ago, seems to have gone unanswered…

As a corollary to this - I am trying to make something similar to rs.GetPoints() - which is how I stumbled on the above problem - but I want to be able to have a pre-existing point used as the first point. So as soon as the method is run, the first point appears on the screen with a rubber band line going to the next point - which will be the first user mouse click (or coordinate entry). I tried to cobble together something using the base RhinoCommon code for rs.GetPoints() as a starting point, but I have not managed to make it work so far. If anyone has some code that does this or some suggestions, it would help me learn something here.

Hi @Helvetosaur,

Does this help any?

import Rhino
import scriptcontext
import System

def AddLine():
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Start of line")
    gp.Get()
    if gp.CommandResult() != Rhino.Commands.Result.Success:
        return

    pt_start = gp.Point()

    gp.SetCommandPrompt("End of line")
    gp.SetBasePoint(pt_start, False)
    gp.DrawLineFromPoint(pt_start, True)
    gp.Get()
    if gp.CommandResult()  !=  Rhino.Commands.Result.Success:
        return

    pt_end = gp.Point()

    v = pt_end - pt_start
    if v.IsTiny(Rhino.RhinoMath.ZeroTolerance):
        return

    id = scriptcontext.doc.Objects.AddLine(pt_start, pt_end)
    if id != System.Guid.Empty:
        scriptcontext.doc.Views.Redraw()

if __name__=="__main__":
    AddLine()

– Dale

1 Like

Hi Dale,

Somewhat, but it’s not really what I am trying to do. I am wanting to get multiple points and have a fixed (pre-supplied) point as the first point, and have the (poly)line drawn dynamically from the first point.

The modification below of your code above works for a line starting from a fixed point, but I haven’t
gotten it to work the way I want with multiple points (yet).

import Rhino
import scriptcontext
import System

def AddLine():
    pt_start = Rhino.Geometry.Point3d(0,0,0)
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("End of line")
    gp.SetBasePoint(pt_start, False)
    gp.DrawLineFromPoint(pt_start, True)
    gp.Get()
    if gp.CommandResult()  !=  Rhino.Commands.Result.Success:
        return

    pt_end = gp.Point()

    v = pt_end - pt_start
    if v.IsTiny(Rhino.RhinoMath.ZeroTolerance):
        return

    id = scriptcontext.doc.Objects.AddLine(pt_start, pt_end)
    if id != System.Guid.Empty:
        scriptcontext.doc.Views.Redraw()
AddLine()

Edit - however now, looking at your code and hacking my existing stuff a bit, I finally got it to work. It needs some cleanup and error checking, but here’s where I am:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def GetPointsCustom1(message1=None, message2=None, base_point=None):
    draw_lines=True #change later
    gp = Rhino.Input.Custom.GetPoint()
    gp.DrawLineFromPoint(base_point,True)
    if message1: gp.SetCommandPrompt(message1)
    gp.SetBasePoint(base_point,False)
    gp.EnableDrawLineFromPoint(True)
    if base_point: rc=[base_point]
    getres = gp.Get()
    if gp.CommandResult()!=Rhino.Commands.Result.Success: return None
    prevPoint = gp.Point()
    rc.append(prevPoint)
    if message2: gp.SetCommandPrompt(message2)
    def GetPointDynamicDrawFunc( sender, args ):
        if len(rc)>1:
            c = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
            args.Display.DrawPolyline(rc, c)
    if draw_lines: gp.DynamicDraw += GetPointDynamicDrawFunc
    while True:
        if draw_lines: gp.DrawLineFromPoint(prevPoint, True)
        gp.SetBasePoint(prevPoint, True)
        getres = gp.Get()
        if getres==Rhino.Input.GetResult.Cancel: break
        if gp.CommandResult()!=Rhino.Commands.Result.Success: return None
        prevPoint = gp.Point()
        rc.append(prevPoint)
    return rc

test=GetPointsCustom1(base_point=Rhino.Geometry.Point3d(0,0,0))
if test:
    sc.doc.Objects.AddPolyline(test)
    sc.doc.Views.Redraw()

Hi @Helvetosaur,

When SR18 is available, you’ll be able to do this:

import Rhino
import scriptcontext as sc

pt_start = Rhino.Geometry.Point3d(0,0,0)

gp = Rhino.Input.Custom.GetPolyline()
gp.SetFirstPoint(pt_start)
rc, polyline = gp.Get()
if rc == Rhino.Commands.Result.Success:
    sc.doc.Objects.AddPolyline(polyline)
    sc.doc.Views.Redraw()

https://mcneel.myjetbrains.com/youtrack/issue/RH-68082
– Dale