Run Fusion commands

The online help already has a sample on listing all the controls in the user interface which also provides the id of  the CommandDefinition that the various controls reference.  You can also get to the sample from many help topics, including “UserInterface.toolbars”

This sample is very useful when positioning your controls within existing Fusion toolbars and panels and positioning your command adjacent to an existing command

However, if you are only interested in the command names and their id‘s then you can get them much simpler.

When you create your command then you create a CommandDefinition object and add it to the UserInterface.commandDefinitions collection.
This collection contains the internal command definitions as well. So you can just iterate through it to get the info you want. In Python it could be:

app = adsk.core.Application.get()
ui = app.userInterface
fileDialog = ui.createFileDialog()
fileDialog.isMultiSelectEnabled = False
fileDialog.title = "Specify result filename"
fileDialog.filter = 'Text files (*.txt)'
fileDialog.filterIndex = 0
dialogResult = fileDialog.showSave()
if dialogResult == adsk.core.DialogResults.DialogOK:
filename = fileDialog.filename
else:
return
commandDefinitions = ui.commandDefinitions
result = ""
for commandDefinition in commandDefinitions:
result += "id = " + commandDefinition.id + "; name = " + commandDefinition.name + "n"
output = open(filename, 'w')
output.writelines(result)
output.close()

You can search the content of the created file to find the id of the CommandDefinition you need. Once you have it you can Execute it – e.g. in Python running the Export command:

cmdDef = ui.commandDefinitions.itemById("ExportCommand")
cmdDef.execute()

Exportcommand

-Adam


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading