Python: How to create a Panel / CommanButton in the Solid Tab

Python: How to create a Panel / CommanButton in the Solid Tab

lichtzeichenanlage
Advisor Advisor
682 Views
2 Replies
Message 1 of 3

Python: How to create a Panel / CommanButton in the Solid Tab

lichtzeichenanlage
Advisor
Advisor

Not sure if I'm using the right terminology but this is what I want to do:

21-06-2020 15-43-07.png

 

This is what I'm doing right now:

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # create panel
        workSpace = ui.workspaces.itemById('FusionSolidEnvironment')
        toolbarPanels = workSpace.toolbarPanels

        # get toolbarPanel
        toolbarPanel = toolbarPanels.itemById(UI_TOOLBAR_PANEL_ID)
        if not toolbarPanel:
            toolbarPanel = toolbarPanels.add(UI_TOOLBAR_PANEL_ID, UI_TOOLBAR_PANEL_NAME, 'SelectPanel', False)

        # create command definition
        commanDefinition = ui.commandDefinitions.itemById(UI_EXPORT_DESIGN_COMMAND_ID)
        if not commanDefinition:
            commanDefinition = ui.commandDefinitions.addButtonDefinition(UI_EXPORT_DESIGN_COMMAND_ID, UI_EXPORT_DESIGN_NAME, UI_EXPORT_DESIGN_TOOLTIP, 'resources/exportIt_designs_icons')
        
        # Adds the commandDefinition to the toolbar panel
        cmdControl = toolbarPanel.controls.addCommand(commanDefinition)
        cmdControl.isPromotedByDefault = True
        
        # add event handler
        onCommandCreated = ExportDesignCommandCreatedHandler()
        commanDefinition.commandCreated.add(onCommandCreated)

        _handlers.append(onCommandCreated)
    except:
        logger.error(traceback.format_exc())

 

Any hint what's wrong in my code?

 

 

 

 

0 Likes
Accepted solutions (1)
683 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @lichtzeichenanlage .

 

I think it is better to use toolsTab.toolbarPanels instead of workSpace.toolbarPanels.

・・・
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # create panel
        # workSpace = ui.workspaces.itemById('FusionSolidEnvironment')
        # toolbarPanels = workSpace.toolbarPanels

        # get toolbarPanels
        allDesignTabs = ui.toolbarTabsByProductType('DesignProductType')
        toolsTab = allDesignTabs.itemById('SolidTab')
        toolbarPanels = toolsTab.toolbarPanels

        # get toolbarPanel
        toolbarPanel = toolbarPanels.itemById(UI_TOOLBAR_PANEL_ID)
        if not toolbarPanel:
・・・
Message 3 of 3

lichtzeichenanlage
Advisor
Advisor

I thought I've tried this. Thanks for the solution. 

0 Likes