Testing something for another thread and ran into this… Below is the standard GetPoints from the rhinoscriptsyntax module, I just added one line (commented out) plus an additional argument at the end:
import rhinoscriptsyntax as rs
import Rhino
def GetPoints(draw_lines=False, in_plane=False, message1=None, message2=None, max_points=None, base_point=None,c_dist=None):
gp = Rhino.Input.Custom.GetPoint()
if message1: gp.SetCommandPrompt(message1)
gp.EnableDrawLineFromPoint( draw_lines )
if in_plane:
gp.ConstrainToConstructionPlane(True)
plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
gp.Constrain(plane, False)
getres = gp.Get()
if gp.CommandResult()!=Rhino.Commands.Result.Success: return None
prevPoint = gp.Point()
rc = [prevPoint]
if max_points is None or max_points>1:
current_point = 1
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 max_points and current_point>=max_points: break
if draw_lines: gp.DrawLineFromPoint(prevPoint, True)
gp.SetBasePoint(prevPoint, True)
#uncomment the following line and test
#gp.ConstrainDistanceFromBasePoint(c_dist)
current_point += 1
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
msg1="Pick first point"
msg2="Pick next point or Enter to finish"
pts=GetPoints(True,False,msg1,msg2,None,None,10.0)
rs.AddPolyline(pts)
If you run this, you can pick a few points and right click to Enter and terminate the GetPoints, then it adds the polyline. When you right click, gp.Get() returns Rhino.Input.GetResult.Cancel so it exits.
Now, uncomment the line in there that I added -
#gp.ConstrainDistanceFromBasePoint(c_dist)
– the idea behind that is to force equal segments of a given length. However when I do that, a right click no longer returns Cancel - it returns a point, just like a left click. Hitting Enter or spacebar the same, it just takes the mouse cursor location as the point. Only Esc cancels.
Is that behavoir intentional or is it buggish? If the second - workarounds?
1 post - 1 participant