Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

7 REPLIES 7
Reply
Message 1 of 8
DonghuiKZ2ET
1795 Views, 7 Replies

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

Hi. I want to create a new toolbar panel.

 

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

 

Thank you.

7 REPLIES 7
Message 2 of 8
liujac
in reply to: DonghuiKZ2ET

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

Message 3 of 8
DonghuiKZ2ET
in reply to: liujac

Thank you very much!

Message 4 of 8
njacobson8PNTR
in reply to: liujac

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. 

Message 5 of 8
TheRealWilliam
in reply to: liujac

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!!

Message 6 of 8
goyals
in reply to: TheRealWilliam

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
Message 7 of 8
TheRealWilliam
in reply to: goyals

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.
Message 8 of 8
goyals
in reply to: TheRealWilliam

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report