Multiple Object Selection w/ Options

Hello,

I am trying to enable multiple objects to be selected w/ command line options & as soon as the command line options change, the selection switched to one object from multiple, code below:


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.GetObject()
    gp.SetCommandPrompt("Get Points & curves")
    
    gFilter = Rhino.DocObjects.ObjectType.Point 
    gFilter |= Rhino.DocObjects.ObjectType.Curve
    gp.GeometryFilter = gFilter
    
    

    # 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)
    
    gp.GetMultiple(1, 0)
    
    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()
        ids = [gp.Object(i).ObjectId for i in range(gp.ObjectCount)]
        if gp.CommandResult()!=Rhino.Commands.Result.Success:
            return gp.CommandResult()
        #if len(ids)>0:
        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()

II can´t heolp you but you know you got elif instead of elseif?

Thanks Jordy, but that’s how you write elseif in python :slight_smile:

BRADLEY ROTHENBERG
Bradley Rothenberg | co-founder | 381-383 Broadway, #203 NY, NY 10013
t. 917.710.1396 e. brad@bradleyrothenberg.com w.bradleyrothenberg.com

twitter l instagram l facebook

Doh. Learned a new thing then. :smiley: Sorry for the trouble.

I know the problem…

on top you got:
gp.GetMultiple(1, 0)

in the while true you got:
get_rc = gp.Get()

change the gp.get() to gp.GetMultiple(1, 0) and its fixed

Move the call to GetMultiple() inside of your while loop, and get rid of the call to Get() inside of your while loop.

Thank you!

BRADLEY ROTHENBERG
Bradley Rothenberg | co-founder | 381-383 Broadway, #203 NY, NY 10013
t. 917.710.1396 e. brad@bradleyrothenberg.com w.bradleyrothenberg.com

twitter l instagram l facebook

FWIW, a similar question was answered incl. Python code in another thread just yesterday