GetObjects options not shown when objects are preselected

I want to set properties of selected objects (using SetUserText). Because each object can have 5 different properties, I want to be able to select which property will be set when the user is prompted to select objects.

This works perfectly when no objects are preselected. But when objects are pre-selected, the command prompt “Select objects” with options is not shown. Why?

def RunCommand():
    go = Rhino.Input.Custom.GetObject()
    go.GroupSelect = True
    
    go.SetCommandPrompt('Select objects')

    index = 0
    go.AddOptionList('Property',['mat','EF','LF','rm1','rm2'],index)
    
    while True:
        get_rc = go.GetMultiple(1,0)
        
        if go.CommandResult()!=Rhino.Commands.Result.Success:
            return go.CommandResult()
        
        elif get_rc==Rhino.Input.GetResult.Option:
            option = go.Option()
            index = option.CurrentListOptionIndex

        elif get_rc == Rhino.Input.GetResult.Object:
            objs = go.Objects()
            setPropertyTo(index,objs)
            break

Hi @mpreisig,

The purpose of GetObject is to pick objects. Thus, if there are pre-selected objects when you call GetObject.GetMultiple, then GetObject has done it’s job.

This is why your code jumps to the elif get_rc == Rhino.Input.GetResult.Object statement.

You’ve got a couple of options:

1.) Disable pre-selection.

go.EnablePreSelect(False, True)

2.) Detect pre-selected objects and prompt for additional options after the fact.

elif get_rc == Rhino.Input.GetResult.Object:
    if go.ObjectsWerePreselected:
        # todo: prompt for options
        break
    else:
        objs = go.Objects()
        setPropertyTo(index,objs)
        break

Here is sample, in C#, that may also help.

http://developer.rhino3d.com/samples/rhinocommon/pre-and-post-pick-objects/

– Dale

1 Like

Thanks a lot Dale, that helped! I’m now asking for the options after selection with the method GetString:

def RunCommand():
    go = Rhino.Input.Custom.GetObject()
    go.GroupSelect = True
    
    go.SetCommandPrompt('Select objects')

    index = 0
    
    while True:
        get_rc = go.GetMultiple(1,0)
        
        if go.CommandResult()!=Rhino.Commands.Result.Success:
            return go.CommandResult()

        elif get_rc == Rhino.Input.GetResult.Object:
            objs = go.Objects()
            
            prop = rs.GetString('Property','mat',['mat','EF','LF','rm1','rm2'])
            
            setPropertyTo(prop,objs)
            break