I’m missing something essential here - I tried a bunch of ways and I’m not getting it…
I want to be able to select several objects but also have a list toggle on the command line. As soon as I change the option, it finishes. There’s supposed to be a loop in there somewhere that I can break out of but I can’t figure it out… TIA, --Mitch
import Rhino
def TestGetObjects_OptionList():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
listValues = ["DoThis", "DoThat", "DoNothing"]
opList = go.AddOptionList("List", listValues, 2)
go.GetMultiple(1,0)
if go.CommandResult()!=Rhino.Commands.Result.Success:
return go.CommandResult()
ids = [go.Object(i).ObjectId for i in range(go.ObjectCount)]
listIndex = go.Option().CurrentListOptionIndex
print ids
print "Chosen option = {}".format(listIndex)
TestGetObjects_OptionList()
How does the code below work? I’m no Python expert and have not tested this, but the same control flow works for me in C#. Note that with an existing selection prior to running the the command, it will complete immediately. Use go.EnablePreselect(False) to prevent this.
import Rhino
def TestGetObjects_OptionList():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
listValues = ["DoThis", "DoThat", "DoNothing"]
opList = go.AddOptionList("List", listValues, 2)
while True:
getResult = go.GetMultiple(1,0)
if getResult == Rhino.Input.Cancel:
return Rhino.Commands.Result.Cancel
elif getResult == Rhino.Input.Option:
listIndex = go.Option().CurrentListOptionIndex
print "Chosen option = {}".format(listIndex)
elif getResult == Rhino.Input.Object:
ids = [go.Object(i).ObjectId for i in range(go.ObjectCount)]
break #break from while loop after objects have been selected
TestGetObjects_OptionList()