Order Icons in a Toolbar Panel

Order Icons in a Toolbar Panel

ebunn3
Advocate Advocate
475 Views
2 Replies
Message 1 of 3

Order Icons in a Toolbar Panel

ebunn3
Advocate
Advocate

Hi,

 

I've pasted in some code below.  I have this code in the Run procedure for each of my Add-Ins.  Problem is the Add-Ins are added, on startup, in alphabetical order and I do not want my icons to appear in this order.  I want to set the order.  I see there is an index function but it is read only.  Is there a way to do this?

 

Thanks in advance for the help.

 

Eric

def run(context):
    """The run function is the main function that runs first when loading the Add-in.
    It will add a toolbar button to the ui which will be controlled by the comPressedEventHandler class functions."""
    ui = None
    global units
    try:
        #get the application
        app = adsk.core.Application.get()
        ui  = app.userInterface

         #Get command definitions & design workspace##################################################################################################
        cmd_def = ui.commandDefinitions
        des_wp = ui.workspaces.itemById('FusionSolidEnvironment')

        # Add the Eco Tab to the Workspace.
        eco_tab = des_wp.toolbarTabs.itemById(eco_Tab)
        if not eco_tab:
            eco_tab = des_wp.toolbarTabs.add(eco_Tab, eco_Tab_Name)

        # Add the Tray Design panel.
        addin_panel = eco_tab.toolbarPanels.itemById(eco_Panel)
        if not addin_panel:
            addin_panel = eco_tab.toolbarPanels.add(eco_Panel, eco_Panel_Name,eco_tab.id, False)
        #Get command definitions & design workspace##################################################################################################


        #Add a button CommandDefininition to that collection
        # folder name (within same directory) for icons 16X16, 32X32 & 64X64.png) (change button properties in global variables on top)
        # ret = readConstants("RevisionNumber.txt")
        comDef = cmd_def.itemById(butName)# + " Rev " + ret[0][1]#this goes after butDialogName
        if not comDef:
            comDef = cmd_def.addButtonDefinition(butName,
            butDialogName,
            tooltip,
            folderName)

        #Grabbing the correct toolbar panel to add the button to
        addinsToolbarPanel = addin_panel
        
        #Adding the button to the toolbar Panel
        tray_ctrl = addin_panel.controls.itemById(butName)
        if not tray_ctrl:
            tray_ctrl = addinsToolbarPanel.controls.addCommand(comDef,controlName)
        #Making the button visible without having to use the dropdown
        tray_ctrl.isPromotedByDefault = True

        #Setting up the handler if the button is pressed
        #Calling the class
        comPressed = comPressedEventHandler()
        comDef.commandCreated.add(comPressed)
        handlers.append(comPressed)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Accepted solutions (1)
476 Views
2 Replies
Replies (2)
Message 2 of 3

boopathi.sivakumar
Autodesk
Autodesk
Accepted solution

Hi @ebunn3 

You can achieve this passing optional argument positionID (reference command id) and isBefore (true if you want to create the command before the reference command)

returnValue = toolbarControls_var.addCommand(commandDefinition, positionID, isBefore)

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-1ed0cfb5-2ad4-4285-9eec-484ef19f2729

 


Boopathi Sivakumar
Senior Technology Consultant

Message 3 of 3

ebunn3
Advocate
Advocate

Thank you so much!

 

Eric

0 Likes