Hi,
First a small complain, RhinoCommon, RhinoPython, and the other APIs are really not helpful for beginner programmers. Same goes for the examples. Very few comments not really explaining what is going on.
Now on the point. Can anyone explain, please…
How can I make the code below draw the line segments between the points while I’m creating them? I am getting its length after all.
Please excuse me for the useless lines, I’m trying to understand how it all works.
import Rhino
import scriptcontext
def zPolyline():
# For this example we will use a GetPoint class, but all of the custom
# "Get" classes support command line options.
gp = Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("GetPoint with options")
# set up the options
intOption = Rhino.Input.Custom.OptionInteger(1, 1, 99)
dblOption = Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9)
boolOption = Rhino.Input.Custom.OptionToggle(True, "Off", "On")
listValues = "Item0", "Item1", "Item2", "Item3", "Item4"
# set up options' defaults
gp.AddOptionInteger("Integer", intOption)
gp.AddOptionDouble("Double", dblOption)
gp.AddOptionToggle("Boolean", boolOption)
listIndex = 3
list = Rhino.Collections.Point3dList
# WHA?
opList = gp.AddOptionList("List", listValues, listIndex)
pl = Rhino.Geometry.Polyline()
while True:
# perform the get operation. This will prompt the user to
# input a point, but also allow for command line options
# defined above
for i in range(0,5):
get_rc = gp.Get()
#if you don't comply with the next if loop keep the command open
if gp.CommandResult()!=Rhino.Commands.Result.Success:
return gp.CommandResult()
#the if loop that completes the command
if get_rc == Rhino.Input.GetResult.Point:
point = gp.Point()
scriptcontext.doc.Objects.AddPoint(point)
scriptcontext.doc.Views.Redraw()
#print "Command line option values are"
#print " Integer =", intOption.CurrentValue
#print " Double =", dblOption.CurrentValue
#print " Boolean =", boolOption.CurrentValue
#print " List =", listValues[listIndex]
print "x= ",point.X,", y= ",point.Y,", z= ",point.Z
pl.Add(point.X,point.Y,point.Z)
print pl.Length
#print list
#
elif get_rc==Rhino.Input.GetResult.Option:
if gp.OptionIndex()==opList:
listIndex = gp.Option().CurrentListOptionIndex
Rhino.Geometry.Polyline(list)
continue
break
return Rhino.Commands.Result.Success
if __name__ == "__main__":
zPolyline()
I know I have a lot to learn, but still reusing pieces of code should be relatively easy. Replacing a thing or two. If a Line requires two points and can be defined as Line(startPt,endPt), then why can’t a Polyline be defined from a list like Polyline(list)? It requries point3dlist, ok, but when I add a point to it as point3dlist.Add(pt.X,pt.Y,pt.Z) it slaps me in the face with an error that there’s one more argument to be given. According to the api this should be “self”… What is going on?
Thanks in advance.
EDIT: Is there plan in the future to abandon pythonscript and stick only with RhinoCommon, because in many examples both are used and this adds to the confusion.