Prepare your add-in for UI Preview

There is a UI Preview available in Fusion 360 providing a tabbed experience. If you enable it then depending on which UI section your add-in is currently trying to add its buttons to, it might fail since some items were replaced with new ones.

UiPreview

UI Preview

E.g. instead of having a single toolbar panel for Sketch with id “SketchPanel” in the “Design” environment (id=FusionSolidEnvironment), now we have multiple of those, inc. “Create” (id=SketchCreatePanel), “Modify” (id=SketchModifyPanel), etc

NewFusionUi

Current vs New UI

In order to make your add-in work in this new environment, you should make sure that if the classic UI item is not available then you try using the new UI item instead:

modelingWorkspace_ = workspaces_.itemById('FusionSolidEnvironment')
toolbarPanels_ = modelingWorkspace_.toolbarPanels
try:
# try to add it to the classic ui item
toolbarPanel_ = toolbarPanels_.itemById('SketchPanel')
toolbarControlsPanel_ = toolbarPanel_.controls
except:
# if it fails, try to add it to the new ui item
toolbarPanel_ = toolbarPanels_.itemById('SketchCreatePanel')
toolbarControlsPanel_ = toolbarPanel_.controls
# etc

You can easily find the list of all workspaces and toolbarPanels available using a simple python script like this:

def listUIParts():
try:
global app, ui
app = adsk.core.Application.get()
ui = app.userInterface
fileDialog = ui.createFileDialog()
fileDialog.isMultiSelectEnabled = False
fileDialog.title = "Select file to save the information to"
fileDialog.filter = 'Text files (*.txt)'
fileDialog.filterIndex = 0
dialogResult = fileDialog.showSave()
if dialogResult == adsk.core.DialogResults.DialogOK:
filename = fileDialog.filename
else:
return
result = ''
for ws in ui.workspaces:
result += 'workspace name: ' + ws.name + ', id: ' + ws.id + 'n'
try:
for tb in ws.toolbarPanels:
result += '  toolbarPanel name: ' + tb.name + ', id: ' + tb.id + 'n'
except:
result += '  toolbarPanels not availablen'
with open(filename, 'w') as outputFile:
outputFile.writelines(result)
except:
if ui:
ui.messageBox('Failed:n{}'.format(traceback.format_exc())) 

For convenience, here is the text file with the result of the above code: UIelements.txt

  • 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