Hi
Is there a way to pin a control (e.g. a Chamfer Feature) to a toolbar panel (for example to a created toolbar panel) through the API in an addin?
(as described in the attached picture)
Solved! Go to Solution.
Solved by BrianEkins. Go to Solution.
The shortcut menu and the "Pin to Shortcuts" functionality was just recently added. The "Pin to Toolbar" functionality has always been available but was previously accessed through the promote option next to each command. The API equivalent of this is the isPromoted property of the CommandControl object. You can also use the isPromotedByDefault so that if the user resets all toolbar customization, it will stay promoted. This in the discussed in this API help topic: http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-F31C76F0-8C74-4343-904C-68FDA9BB8B4C
The "Pin to Shortcuts" capability is not supported by the API.
Thanks, that was exactly what I was looking for!
I did not find a way to directly pin a command to another toolbar panel, but adding the command to a new toolbar and pinning it afterwards works just fine.
Here is the code snippet for anyone wondering for the Chamfer Command:
# create new toolbar workSpace = ui.workspaces.itemById('FusionSolidEnvironment') tbPanels = workSpace.toolbarPanels global tbPanel tbPanel = tbPanels.itemById('ShaftPanel') if tbPanel: tbPanel.deleteMe() tbPanel = tbPanels.add('NewPanelID', 'NewPanelName', 'SelectPanel', False) # get existing command by ID cmdDefChamfer = ui.commandDefinitions.itemById('FusionChamferCommand') # add and pin the command to new toolbar button = tbPanel.controls.addCommand(cmdDefChamfer) button.isPromoted = True
Thanks again!
Dear Stefan. Good afternoon, Could you send a full page with the python code for the Pin Feature to toolbar solution. I try to understand a similar problem and your script would help me a lot. Thank you in advance Dmitri
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()))