GetOptionDouble - 2 inter-related numbers

The goal was to have an upper and lower bound to choose simultaneously on the command line, rather than one after the other. The idea is that the user cannot input an upper bound less than the lower bound and vice-versa; the whole thing to remain “live” until the user hits Enter to OK, or Esc to bail.

I struggled with this for awhile until I had a lightbulb event, in the end it turned out to be relatively simple. So I though I’d throw it out here for anyone who might consider it useful for any of their scripts.

What’s interesting about the multiple options on the same line is that you can change your mind on any of them in mid-course and continue, but that ability actually costs you extra keystrokes over entering data sequentially - so it’s likely to be slower than just typing x enter y enter. So this is merely presented as an exercise for fun… FWIW. --Mitch

Edit - Unfortunately, although this works fine on a Windows command line, it does not work correctly on Mac.

import Rhino
import scriptcontext

def CommandLineOptions(msg_0,msg_1,val_0,val_1):
    go = Rhino.Input.Custom.GetOption()
    go.SetCommandPrompt("SetValues")
    
    while True:
        go.ClearCommandOptions()
        dblOption0 = Rhino.Input.Custom.OptionDouble(val_0,False,val_1)
        go.AddOptionDouble(msg_0, dblOption0)
        dblOption1 = Rhino.Input.Custom.OptionDouble(val_1,True,val_0)
        go.AddOptionDouble(msg_1, dblOption1)
        go.AcceptNothing(True)
        get_rc = go.Get()
        if get_rc==Rhino.Input.GetResult.Cancel:
            return
        elif get_rc==Rhino.Input.GetResult.Option:
            val_0=dblOption0.CurrentValue
            val_1=dblOption1.CurrentValue
            continue
        break
    return dblOption0.CurrentValue,dblOption1.CurrentValue

result=CommandLineOptions("Lower","Upper",1.0,2.0)
if result is None: print "Command cancelled"
else: print "Lower value={} ; Upper value={}".format(result[0],result[1])

I haven’t tried this on Rhino for Mac - what happens?