Identify selected (clicked) QAT ListItem from within a CommandEventHandler

Identify selected (clicked) QAT ListItem from within a CommandEventHandler

rgeyer
Explorer Explorer
533 Views
1 Reply
Message 1 of 2

Identify selected (clicked) QAT ListItem from within a CommandEventHandler

rgeyer
Explorer
Explorer

How can I identify which ListItem  ( within an initialized ListControlDefinitionListItem's collection ) is selected by the user?  

 

These QAT commands ( as they are currently constructed ) do not change any values within Fusion 360.  I need them to call an external process with command arguments derived from the button selected.

 

The CommandEventHandler's args allow for the initialization of the command.parentCommandDefinition.id, but I need a way to retrieve the selected-child command's names and/or ids.

 

With this in mind, can the ListControlDefinitionListItem's child commands be identified from within a CommandEventHandler

 

If this must be done in an InputChangedEventHandler, how do I  get the listItems within the QAT to trigger that event?  

 

The current code for the QAT commands is as follows:

 commandDefinitions_ = ui.commandDefinitions
toolbars_ = ui.toolbars toolbarQAT_ = toolbars_.itemById('QAT') toolbarControlsQAT_ = toolbarQAT_.controls # add a ListControlDefinition to the Quick Access Toolbar listCmdToolbarCtlQAT_ = toolbarControlsQAT_.itemById(listCmdIdOnQAT) if not listCmdToolbarCtlQAT_: listCmdDefinitionQAT_ = commandDefinitions_.itemById(listCmdIdOnQAT) if not listCmdDefinitionQAT_: listCmdDefinitionQAT_ = commandDefinitions_.addListDefinition(listCmdIdOnQAT, commandName, adsk.core.ListControlDisplayTypes.StandardListType, index_icon) listItems_ = adsk.core.ListControlDefinition.cast(listCmdDefinitionQAT_.controlDefinition).listItems listItems_.add('Index', True, index_icon)
listItems_.add('Log In', False, login_icon)
listItems_.add('Log Out', False, logout_icon) listItems_.add('Post', False, put_icon) listItems_.add('Put', False, post_icon) listItems_.add('Get', False, get_icon) onListCommandCreated = CommandCreatedEventHandlerQAT() listCmdDefinitionQAT_.commandCreated.add(onListCommandCreated) # Persist handler references: handlers.append(onListCommandCreated) listCmdToolbarCtlQAT_ = toolbarControlsQAT_.addCommand(listCmdDefinitionQAT_) listCmdToolbarCtlQAT_.isVisible = True ui.messageBox(('Index command list has been successfully added to the Quick Access Toolbar'))

 

I'm able to pass the command arguments using standard commandDefinitions like the one shown below, however, I haven't found a way to accomplish the same thing on the QAT using listItems.

  

        # command definitions
        index_command = commandDefinitions_.itemById(index_cmd_id)
        if not index_command:
            index_command = commandDefinitions_.addButtonDefinition(index_cmd_id, 'Index', ".com", './resources/index')

        index_command.commandCreated.add(onCommandCreated)

        # persist the handler references
        onInputChanged = InputChangedHandler()
        handlers.append(onCommandCreated)
        handlers.append(onInputChanged)

        # add commands to the addins panel in modeling workspace
        workspaces_ = ui.workspaces
        modelingWorkspace_ = workspaces_.itemById(workspaceToUse)
        toolbarPanels_ = modelingWorkspace_.toolbarPanels
        toolbarPanel_ = toolbarPanels_.itemById(addins_panel) 
        addins_control_panel = toolbarPanel_.controls
        
        # add the commands to the the addins panel
        index_control = addins_control_panel.itemById(index_cmd_id)
        if not index_control:
            index_control = addins_control_panel.addCommand(index_command, 'index')
            index_control.isVisible = True

  

Any suggestions would be appreciated. Thank you. 

 

0 Likes
534 Views
1 Reply
Reply (1)
Message 2 of 2

marshaltu
Autodesk
Autodesk

Hello,

 

If you have CommandEventArgs object, you would be able to get selected item by the following codes:

 

        cmddef = args.command.parentCommandDefinition
        listctldef = adsk.core.ListControlDefinition.cast(cmddef.controlDefinition)
        selecteditem = listctldef.lastSelected

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes