Last active
June 3, 2018 19:57
-
-
Save zooid/58a863b3bfb9798d08ac94eb0d451e9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Rhino | |
import scriptcontext as sc | |
import rhinoscriptsyntax as rs | |
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") | |
numPoints = 2 | |
numPointsMin = 1 | |
numPointsMax = 99 | |
# set up the options | |
intOption = Rhino.Input.Custom.OptionInteger(numPoints, numPointsMin, numPointsMax) | |
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(numPoints) | |
# 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() | |
sc.doc.Objects.AddPoint(point) | |
#list.Add(point.X,point.Y,point.Z) | |
pl.Add(point) | |
sc.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 | |
print pl.Length | |
print list | |
print pl | |
elif get_rc==Rhino.Input.GetResult.Option: | |
if gp.OptionIndex()==opList: | |
listIndex = gp.Option().CurrentListOptionIndex | |
continue | |
sc.doc.Objects.AddPolyline(pl) | |
break | |
return Rhino.Commands.Result.Success | |
if __name__ == "__main__": | |
zPolyline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment