OptionToggle for >2 options


#1

Hello all,

I am rather new to python coding in rhino. I have been developing a python code that allows the user to initially define certain dimensions (via Rhino.Input.Custom.OptionDouble & gp.AddOptionDouble) as well as some boolean options (via Rhino.Input.Custom.OptionToggle & gp.AddOptionToggle). I am curious if anyone knows of a tool similar to OptionToggle but one that allows the user to select from >2 options. All of these options are currently performed in the command prompt. It is my hope to refrain from using additional dialogue or list boxes. Thank you.


(Dale Fugier) #2

Hi Max,

I believe you are looking for this:

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOptionList_1.htm

Let me know if you need a Python sample…

– Dale


(Dale Fugier) #3

Actually, there is a nice example of this here:

http://developer.rhino3d.com/samples/rhinocommon/add_command_line_options/

– Dale


#4

Hello Dale,

Thanks for the help. I have been able to get the list of options in the command window. I am still having difficulty setting and getting the document data. This is the first portion of my code. You can see I originally set it up as an optiontoggle but now that I have exceeded 2 options, I need to expand to a optionlist (for doortype). Any advice would be greatly appreciated.

def GetWP():
    gp=Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Select Lower Work Point")
    if rs.GetDocumentData("Door","sillheight"):
        sillheightOption = Rhino.Input.Custom.OptionDouble(float(rs.GetDocumentData("Door","sillheight"))/rs.UnitScale(8),1/rs.UnitScale(8),100/rs.UnitScale(8)) #update values in metric(?), then converted to imperial (8)
    else:
        sillheightOption = Rhino.Input.Custom.OptionDouble(10/rs.UnitScale(8),1/rs.UnitScale(8),100/rs.UnitScale(8))
    if rs.GetDocumentData("Door","doorheight"):
        doorheightOption = Rhino.Input.Custom.OptionDouble(float(rs.GetDocumentData("Door","doorheight"))/rs.UnitScale(8),1/rs.UnitScale(8),200/rs.UnitScale(8)) #last 2 values set the bounds
    else:
        doorheightOption = Rhino.Input.Custom.OptionDouble(100/rs.UnitScale(8),1/rs.UnitScale(8),200/rs.UnitScale(8))
    if rs.GetDocumentData("Door","doorwidth"):
        doorwidthOption = Rhino.Input.Custom.OptionDouble(float(rs.GetDocumentData("Door","doorwidth"))/rs.UnitScale(8),1/rs.UnitScale(8),150/rs.UnitScale(8))
    else:
        doorwidthOption = Rhino.Input.Custom.OptionDouble(100/rs.UnitScale(8),1/rs.UnitScale(8),150/rs.UnitScale(8))

    if rs.GetDocumentData("Door","doortype"):
        if rs.GetDocumentData("Door","doortype") == "True":
            doortypeOption = Rhino.Input.Custom.OptionToggle(True, "Watertight", "Weathertight")
        else:
            doortypeOption = Rhino.Input.Custom.OptionToggle(False,"Watertight", "Weathertight")
    else:
        doortypeOption = Rhino.Input.Custom.OptionToggle(True,"Watertight", "Weathertight")
    if rs.GetDocumentData("Door","throw"):
        if rs.GetDocumentData("Door","throw") == "True":
            throwOption = Rhino.Input.Custom.OptionToggle(True, "negX","posX")
        else:
            throwOption = Rhino.Input.Custom.OptionToggle(False,"negX","posX")
    else:
        throwOption = Rhino.Input.Custom.OptionToggle(True,"negX","posX")
    if rs.GetDocumentData("Door","swinghand"):
        if rs.GetDocumentData("Door","swinghand") == "True":
            swinghandOption = Rhino.Input.Custom.OptionToggle(True, "Left","Right")
        else:
            swinghandOption = Rhino.Input.Custom.OptionToggle(False, "Left","Right")
    else:
        swinghandOption = Rhino.Input.Custom.OptionToggle(True,"Left","Right")
    if rs.GetDocumentData("Door","swingdir"):
        if rs.GetDocumentData("Door","swingdir") == "True":
            swingdirOption = Rhino.Input.Custom.OptionToggle(True, "Reversed","Away")
        else:
            swingdirOption = Rhino.Input.Custom.OptionToggle(False, "Reversed","Away")
    else:
        swingdirOption = Rhino.Input.Custom.OptionToggle(True,"Reversed","Away")
    if rs.GetDocumentData("Door","degopen"):
        degopenOption = Rhino.Input.Custom.OptionDouble(float(rs.GetDocumentData("Door","degopen")),0,180)
    else:
        degopenOption = Rhino.Input.Custom.OptionDouble(0,0,180)
    gp.AddOptionDouble("SillHeight_"+rs.UnitSystemName(True,False,True,True), sillheightOption)
    gp.AddOptionDouble("DoorHeight_"+rs.UnitSystemName(True,False,True,True), doorheightOption)
    gp.AddOptionDouble("DoorWidth_"+rs.UnitSystemName(True,False,True,True), doorwidthOption)
    gp.AddOptionToggle("DoorType",doortypeOption) #################################
    #gp.AddOptionList("DoorType",("Weathertight","Watertight","Joiner"),0)
    gp.AddOptionToggle("Throw",throwOption)
    gp.AddOptionToggle("SwingHand",swinghandOption)
    gp.AddOptionToggle("SwingDir",swingdirOption)
    gp.AddOptionDouble("DegreeOpen",degopenOption)
    while True:
        get_rc = gp.Get()
        if gp.CommandResult()!=Rhino.Commands.Result.Success:
            return gp.CommandResult()
        scriptcontext.escape_test()
        if get_rc==Rhino.Input.GetResult.Point:
            WP = gp.Point()
            sillheight = sillheightOption.CurrentValue
            rs.SetDocumentData("Door","sillheight",str(sillheight*rs.UnitScale(8)))
            #doorheight = doorheightOption.CurrentValue
            doorheightclear = doorheightOption.CurrentValue
            rs.SetDocumentData("Door","doorheight",str(doorheightclear*rs.UnitScale(8)))
            doorwidth = doorwidthOption.CurrentValue
            rs.SetDocumentData("Door","doorwidth",str(doorwidth*rs.UnitScale(8)))
            doortype = doortypeOption.CurrentValue
            rs.SetDocumentData("Door","doortype",str(doortype))
            throw = throwOption.CurrentValue
            rs.SetDocumentData("Door","throw",str(throw))
            swinghand = swinghandOption.CurrentValue
            rs.SetDocumentData("Door","swinghand",str(swinghand))
            swingdir = swingdirOption.CurrentValue
            rs.SetDocumentData("Door","swingdir",str(swingdir))
            degopen = degopenOption.CurrentValue
            rs.SetDocumentData("Door","degopen",str(degopen))
        elif get_rc==Rhino.Input.GetResult.Option:
            continue
        break
    return WP, sillheight, doorheightclear, doorwidth, doortype, throw, swinghand, swingdir, degopen

(Dale Fugier) #5

Hi Max,

In trying to make your script easier to read and understand, and to make it a bit more portable, I ended up taking a sledgehammer to it (see attached). I hope you don’t mind. :wink:

Max.py (6.9 KB)

I’ve added a class that maintains all of the door parameters and reads and writes the document data. This makes the data a bit more portable and maintainable.

I’ve also hooked up the options list stuff.

I haven’t tested this a whole lot. But let me know if this helps.

– Dale