Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The property to rename a command button in the UI:
CommandDefinition.name
It is documented here: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-cdf53108-bcaf-418e-b678-f041f2e207c4
And it won't work, when I set it, it doesn't change the name in the UI. The tooltip property changes the name of the tooltip fine, but the name property doesn't change the name of the command button in the UI.
Here's my code:
import adsk.core, adsk.fusion, traceback
button_names = [("Start calc Add-In", "Starts the calculation Add-In."),
("Stop calc Add-In", "Stops the calculation Add-In.")]
panel_id = "SolidScriptsAddinsPanel"
command_id = "calc_add_in"
handlers = []; running = False
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
def msg(message): ui.messageBox(str(message))
class CommandCreatedEventHandlerPanel(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global running
try:
running = not running
commandDefinitionPanel_.name = button_names[int(running)][0]
commandDefinitionPanel_.tooltip = button_names[int(running)][1]
msg("Calculation "+("started" if running else "stopped"))
except:
if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
def run(context):
global commandDefinitionPanel_
try:
workspaces_ = ui.workspaces
modelingWorkspace_ = workspaces_.itemById("FusionSolidEnvironment")
toolbarPanels_ = modelingWorkspace_.toolbarPanels
toolbarPanel_ = toolbarPanels_.itemById(panel_id)
toolbarControlsPanel_ = toolbarPanel_.controls
toolbarControlPanel_ = toolbarControlsPanel_.itemById(command_id)
if not toolbarControlPanel_:
commandDefinitionPanel_ = ui.commandDefinitions.itemById(command_id)
if not commandDefinitionPanel_:
commandDefinitionPanel_ = ui.commandDefinitions.addButtonDefinition(
command_id, *button_names[0])
toolbarControlPanel_ = toolbarControlsPanel_.addCommand(commandDefinitionPanel_)
toolbarControlPanel_.isVisible = True
onCommandCreated = CommandCreatedEventHandlerPanel()
commandDefinitionPanel_.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
except:
if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
def commandControlByIdForPanel(id):
if not id:
ui.messageBox("commandControl id is not specified")
return None
workspaces_ = ui.workspaces
modelingWorkspace_ = workspaces_.itemById("FusionSolidEnvironment")
toolbarPanels_ = modelingWorkspace_.toolbarPanels
toolbarPanel_ = toolbarPanels_.itemById(panel_id)
toolbarControls_ = toolbarPanel_.controls
toolbarControl_ = toolbarControls_.itemById(id)
return toolbarControl_
def destroy_object(item):
if item and item.isValid: item.deleteMe()
def stop(context):
global running
try:
running = False
commandDefinitions_ = ui.commandDefinitions
commandDefinition_ = commandDefinitions_.itemById(command_id)
destroy_object(commandDefinition_)
commandControlPanel_ = commandControlByIdForPanel(command_id)
destroy_object(commandControlPanel_)
except:
if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
Solved! Go to Solution.