How do I add a graphic to my new toolbar item?

How do I add a graphic to my new toolbar item?

OceanHydroAU
Collaborator Collaborator
707 Views
1 Reply
Message 1 of 2

How do I add a graphic to my new toolbar item?

OceanHydroAU
Collaborator
Collaborator

I'm struggling with the ToolbarPanels.add Method ( https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-165e8619-babe-4448-a79b-ff7d5dfac8aa )

 

My icon for my button is not showing up:-

pic 2020-03-23 00.10.14_23.png

 

I've got a ./resources folder with 32x32.png and 64x64.png etc in it, but I can't work out how I tell the ".add" method to *use* them - here's my code.  I did manage to figure it out for the commands, but that's becuase those methods let you tell it where the resource folder is - how do I tell ToolbarPanels.add this?

 

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

tbPanel = None
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        workSpace = ui.workspaces.itemById('FusionSolidEnvironment')
        tbPanels = workSpace.toolbarPanels
        
        global tbPanel
        tbPanel = tbPanels.itemById('NewPanel')
        if tbPanel:
            tbPanel.deleteMe()
        tbPanel = tbPanels.add('NewPanel', 'AirFoil Tools', 'SelectPanel', False)  # This fails to put any button onto my new panel item.
        
        # Empty panel can't be displayed. Add a command to the panel
        cmdDef = ui.commandDefinitions.itemById('NewCommand')
        if cmdDef:
            cmdDef.deleteMe()
        cmdDef = ui.commandDefinitions.addButtonDefinition('NewCommand', 'Import DAT', 'Load and optimise a dat to a spline', './resources') # This works, with its own tiny button.
        tbPanel.controls.addCommand(cmdDef)
        
        ui.messageBox('Hello addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        if tbPanel:
            tbPanel.deleteMe()
        
        ui.messageBox('Stop addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
Accepted solutions (1)
708 Views
1 Reply
Reply (1)
Message 2 of 2

kandennti
Mentor
Mentor
Accepted solution

Hi @OceanHydroAU .

 

Use the isPromotedByDefault property of the CommandControl object.

・・・
        # Empty panel can't be displayed. Add a command to the panel
        cmdDef = ui.commandDefinitions.itemById('NewCommand')
        if cmdDef:
            cmdDef.deleteMe()
        cmdDef = ui.commandDefinitions.addButtonDefinition('NewCommand', 'Import DAT', 'Load and optimise a dat to a spline', './resources') # This works, with its own tiny button.
        # tbPanel.controls.addCommand(cmdDef)
        cmdControl :adsk.core.CommandControl = tbPanel.controls.addCommand(cmdDef) # here
        cmdControl.isPromotedByDefault = True # here

        ui.messageBox('Hello addin')
・・・
0 Likes