This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
/
ex_commandlineoptions.py
47 lines (41 loc) · 1.76 KB
/
ex_commandlineoptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Rhino
import scriptcontext
def CommandLineOptions():
# 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"
gp.AddOptionInteger("Integer", intOption)
gp.AddOptionDouble("Double", dblOption)
gp.AddOptionToggle("Boolean", boolOption)
listIndex = 3
opList = gp.AddOptionList("List", listValues, listIndex)
while True:
# perform the get operation. This will prompt the user to
# input a point, but also allow for command line options
# defined above
get_rc = gp.Get()
if gp.CommandResult()!=Rhino.Commands.Result.Success:
return gp.CommandResult()
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]
elif get_rc==Rhino.Input.GetResult.Option:
if gp.OptionIndex()==opList:
listIndex = gp.Option().CurrentListOptionIndex
continue
break
return Rhino.Commands.Result.Success
if __name__ == "__main__":
CommandLineOptions()