Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Problem with selectionEventArgs.activeInput

j.han97
Advocate

Problem with selectionEventArgs.activeInput

j.han97
Advocate
Advocate

Hi all,

 

I am using selectionEventHandler to read new selection of my selectionCommandInput. However, I could not access the selectionCommandInput using the selectionEventArgs.activeInput, instead it returns a NoneType object.

 

I have created a short sample of code to demonstrate this problem. Please find the code below or download the zip file which contains the code and the required items (an icon and a simple model for testing) if you need it.

 

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

class selections_commandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    
    def notify(self, args):
        try:
            command = adsk.core.CommandCreatedEventArgs.cast(args).command
            inputs = command.commandInputs
            selection = inputs.addSelectionInput('selection', 'Select', 'Click on anything to select')

            #Connect to events
            #Select
            selections_select = selections_selectEventHandler()
            command.select.add(selections_select)
            _handlers.append(selections_select)
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class selections_selectEventHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    
    def notify(self, args):
        try:
            active_input = adsk.core.SelectionEventArgs.cast(args).activeInput
            _ui.messageBox('Active input: %s'%active_input.classType())
                
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

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

def run(context):
    try:
        #Get command definitions & design workspace
        cmd_def = _ui.commandDefinitions
        des_wp = _ui.workspaces.itemById('FusionSolidEnvironment')

        #Get tools tab
        tools_tab = des_wp.toolbarTabs.itemById('ToolsTab')
        
        #Get add-in panel
        addin_panel = tools_tab.toolbarPanels.itemById('SolidScriptsAddinsPanel')
            
        selection_cmdDef = cmd_def.itemById('SelectionTest_cmd')
        if not selection_cmdDef:
            selection_cmdDef = cmd_def.addButtonDefinition('SelectionTest_cmd', 'Select', 'Selection test', './resources/select')
        selection_ctrl = addin_panel.controls.itemById('SelectionTest_cmd')
        if not selection_ctrl:
            selection_ctrl = addin_panel.controls.addCommand(selection_cmdDef)
        
        selection_ctrl.isVisible = True; selection_ctrl.isPromoted = True; selection_ctrl.isPromotedByDefault = True
        
        #Connect to commandCreatedEvent
        selection_commandCreated = selections_commandCreatedEventHandler()
        selection_cmdDef.commandCreated.add(selection_commandCreated)
        _handlers.append(selection_commandCreated)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    try:
        _ui.messageBox('Stop addin')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 What am I missing here? All suggestions are hugely appreciated.

0 Likes
Reply
Accepted solutions (1)
273 Views
2 Replies
Replies (2)

tykapl.breuil
Advocate
Advocate
Accepted solution

I think that what you did should work, it is probably a bug in the api or a problem in the docuementation.

 

In the mean time you can use args.firingEvent.activeInput which does work.

1 Like

j.han97
Advocate
Advocate

Hi @tykapl.breuil ,

 

Thank you very much for your help. It works perfectly!

1 Like