For who is interested, an addIn example to pin a command to a toolbar pane (the ./resources folder needs to be created with optional icon png's)
import adsk.core, adsk.fusion, adsk.cam, traceback
handlers = []
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
commandId = 'myTest'
class ReloadModulesCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
_ui.messageBox('Test succesfull')
except:
_ui.messageBox('ReloadModulesCommandExecuteHandler executed failed: {}'.format(traceback.format_exc()))
# Event handler for the commandCreated event.
class ReloadModulesCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
command = args.command
onExecute = ReloadModulesCommandExecuteHandler()
command.execute.add(onExecute)
handlers.append(onExecute)
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def deletePanel(id :str):
workSpace = _ui.workspaces.itemById('FusionSolidEnvironment')
panels = workSpace.toolbarPanels
panel = panels.itemById(id)
if panel:
panel.deleteMe()
def run(context):
try:
global _ui, _app, commandId
_app = adsk.core.Application.get()
_ui = _app.userInterface
# Add reload modules command.
reloadModulesCmdDef = _ui.commandDefinitions.itemById(commandId)
if not reloadModulesCmdDef:
reloadModulesCmdDef = _ui.commandDefinitions.addButtonDefinition(
commandId,
'Test',
'Test description',
'./resources'
)
# Connect to Command Created event.
onCommandCreated = ReloadModulesCommandCreatedHandler()
reloadModulesCmdDef.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
# delete panel (if exists)
deletePanel(commandId + 'Panel')
# create new toolbar
workSpace = _ui.workspaces.itemById('FusionSolidEnvironment')
panels = workSpace.toolbarPanels
panel = panels.add(commandId + 'Panel', 'NewPanelName', 'SelectPanel', False)
# add and pin the command to new toolbar
button = panel.controls.addCommand(reloadModulesCmdDef)
button.isPromoted = True
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
# Delete controls and associated command definitions created by this add-ins
panel = _ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cmdControl = panel.controls.itemById(commandId)
if cmdControl:
cmdControl.deleteMe()
cmdDef = _ui.commandDefinitions.itemById(commandId)
if cmdDef:
cmdDef.deleteMe()
deletePanel(commandId + 'Panel')
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))