I’m looking at the python script on this page which I literally just copied here since it shows what I’m wondering about. https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOptionList_1.htm
So it asks for an object and then there is an option in the commandline to change the display mode for that object. When I click on that option in the menu and choose the display mode all works fine.
The problem is:
I would assume, based on how rhino commands work, that if I press enter here that it chooses the “Wireframe” default option. But instead, it now just exits the script without changing the display mode, as if you would press esc. How do I take the default input from this option when pressing enter and still cancel when pressing esc instead?
import Rhino
import scriptcontext
def ObjectDisplayMode():
filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select mesh or surface", True, filter)
if rc != Rhino.Commands.Result.Success: return rc;
viewportId = scriptcontext.doc.Views.ActiveView.ActiveViewportID
attr = objref.Object().Attributes
if attr.HasDisplayModeOverride(viewportId):
print "Removing display mode override from object"
attr.RemoveDisplayModeOverride(viewportId)
else:
modes = Rhino.Display.DisplayModeDescription.GetDisplayModes()
mode = None
if len(modes) == 1:
mode = modes[0]
else:
go = Rhino.Input.Custom.GetOption()
go.SetCommandPrompt("Select display mode")
str_modes = []
for m in modes:
s = m.EnglishName.replace(" ","").replace("-","")
str_modes.append(s)
go.AddOptionList("DisplayMode", str_modes, 0)
if go.Get()==Rhino.Input.GetResult.Option:
mode = modes[go.Option().CurrentListOptionIndex]
if not mode: return Rhino.Commands.Result.Cancel
attr.SetDisplayModeOverride(mode, viewportId)
scriptcontext.doc.Objects.ModifyAttributes(objref, attr, False)
scriptcontext.doc.Views.Redraw()
if __name__=="__main__":
ObjectDisplayMode()