set selectionLimits with multiple selectionInputs

set selectionLimits with multiple selectionInputs

m0d0
Contributor Contributor
626 Views
1 Reply
Message 1 of 2

set selectionLimits with multiple selectionInputs

m0d0
Contributor
Contributor

Hi,

 

I am not sure if I am misunderstanding the correct use of the SelectionCommandInput.setSeklectionLimits() function.

The code below should create two selection inputs, each needing at least one selected body for being a valid input.

So I thought the ok-button will turn only clickable only if both selection inputs certify this condition (like an AND statement), but it seems like the OK-button turns clickable if a single input changes to a valid selection and is turned unclickable at the moment a  single selection gets invalid.

Is this the intended behaviour? In this case, I guess, I need to use a ValidateInputsEvent, right?

Or is there something wrong with my code?

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

_handlers = []
_app = adsk.core.Application.get()
_ui = _app.userInterface

_cmdPanel = 'SolidScriptsAddinsPanel'
_cmdId = 'AVeryUniqueCmdId'

def run(context):
    design = adsk.fusion.Design.cast(_app.activeProduct)    
    commandDefinitions = _ui.commandDefinitions
    cmdDef = commandDefinitions.itemById(_cmdId)
    if not cmdDef:
        cmdDef = commandDefinitions.addButtonDefinition(_cmdId,'Test Cmd','tooltip',"")

    onCommandCreated = TestCommandCreatedHandler()
    cmdDef.commandCreated.add(onCommandCreated)
    _handlers.append(onCommandCreated)

    _ui.allToolbarPanels.itemById(_cmdPanel).controls.addCommand(cmdDef)


def stop(context):
    try:
        cmdDef = _ui.commandDefinitions.itemById(_cmdId)
        if cmdDef:
            cmdDef.deleteMe()
        buttonControl = _ui.allToolbarPanels.itemById(_cmdPanel).controls.itemById(_cmdId)
        if buttonControl:
            buttonControl.deleteMe()
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class TestCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            _ui.messageBox('command execution')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class TestCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):    
    def __init__(self):
        super().__init__()        
    def notify(self, args):
        try:
            cmd = args.command

            onExecute = TestCommandExecuteHandler()
            cmd.execute.add(onExecute)
            _handlers.append(onExecute)

            inputs = cmd.commandInputs

            selInput = inputs.addSelectionInput('id1','name','promp')
            selInput.addSelectionFilter('Bodies')
            selInput.setSelectionLimits(1,0)

            selInput2 = inputs.addSelectionInput('id2','name2','promp')
            selInput2.addSelectionFilter('Bodies')
            selInput2.setSelectionLimits(1,0)
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

I would appreciate any ideas.

 

Thanks, m0dd0

0 Likes
Accepted solutions (1)
627 Views
1 Reply
  • API
Reply (1)
Message 2 of 2

nnikbin
Collaborator
Collaborator
Accepted solution

Hi @m0d0 

It seems to be a bug. I have reported it here in 2016.