Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to create a new toolbar panel with API(Python)

Anonymous

How to create a new toolbar panel with API(Python)

Anonymous
Not applicable

Hi. I want to create a new toolbar panel.

 

Could you give me a example code to create a new toolbar panel?

 

Thank you.

0 Likes
Reply
2,243 Views
7 Replies
Replies (7)

liujac
Alumni
Alumni

Hi,

 

The addin below demonstrates how to create a new toolbar panel.

 

import adsk.core, adsk.fusion, adsk.cam, traceback

tbPanel = None
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        workSpace = ui.workspaces.itemById('FusionSolidEnvironment')
        tbPanels = workSpace.toolbarPanels
        
        global tbPanel
        tbPanel = tbPanels.itemById('NewPanel')
        if tbPanel:
            tbPanel.deleteMe()
        tbPanel = tbPanels.add('NewPanel', 'New Panel', 'SelectPanel', False)
        
        # Empty panel can't be displayed. Add a command to the panel
        cmdDef = ui.commandDefinitions.itemById('NewCommand')
        if cmdDef:
            cmdDef.deleteMe()
        cmdDef = ui.commandDefinitions.addButtonDefinition('NewCommand', 'New Command', 'Demo for new command')
        tbPanel.controls.addCommand(cmdDef)
        
        ui.messageBox('Hello addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        if tbPanel:
            tbPanel.deleteMe()
        
        ui.messageBox('Stop addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thanks,

Jack

0 Likes

Anonymous
Not applicable

Thank you very much!

0 Likes

Anonymous
Not applicable

Hey. I've got a python script I already wrote and would like to make a button for this... Can you explain how to add this premade script? can it be linked? or does this need to be just written into the above code. 

0 Likes

TheRealWilliam
Contributor
Contributor

Hi, when I add this code to a fresh new custom Add-In, then Fusion360 crashes as soon as I click on the 'Tools' Ribbon on top of the program. This happens each time. Any ideo what is going wrong...? Thanks!!

0 Likes

goyals
Autodesk
Autodesk

Fusion might be asking to send the report to Autodesk when it crashes. May I know the number you see at the last page after submitting the report so I can look at it. It would be easy to investigate if you can share the script.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes

TheRealWilliam
Contributor
Contributor

So, here is what I did:

I created a new addin and clicked 'Edit'. Spyder2 opened, and I pasted the code from the user above, replacing everything in the document. I saved the file, and clicked 'Run' in the Fusion360 Addins panel. Then Fusion crashed instantly.

I submitted the report, here ist the number:

Thank you for sending your error report CER_178339672 to Autodesk.
0 Likes

goyals
Autodesk
Autodesk

Thank you for sharing the report number. I tried the steps you mentioned on my machine locally but not seeing the crash. May be under specific situation, Fusion is crashing while trying this workflow. We already have a ticket,FUS-42182, in our internal system to look in to this. I will update you once it is resolved or we might reach out to you to get some more inputs to investigate it.

 

In case it is blocking your work, you can try adding your command in to an existing toolbar.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes