Unable to place my toolbar panel before any built-in ones

Unable to place my toolbar panel before any built-in ones

soswow
Advocate Advocate
260 Views
2 Replies
Message 1 of 3

Unable to place my toolbar panel before any built-in ones

soswow
Advocate
Advocate

 

I the problematic line in code below is this one:

 

`

panel = ui.workspaces.itemById('FusionSolidEnvironment').toolbarTabs.itemById('SolidTab').toolbarPanels.add("sashasPanelId","My Panel","SolidCreatePanel",False
`
No matter what I tried I can't put my panel anywhere but last position in solid toolbar Tab.

 

here is a full addin code:

 

import adsk.core, adsk.fusion, adsk.cam, traceback
from importlib import reload
from . import my_module

# Global list to keep all event handlers in scope.
# This is only needed with Python.
handlers = []

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Get the CommandDefinitions collection.
        cmdDefs = ui.commandDefinitions
        
        # Create a button command definition.
        buttonSample = cmdDefs.addButtonDefinition('MyButtonDefIdPython', 
                                                   'Python Sample Button', 
                                                   'Sample button tooltip',
                                                   './Resources')
        
        # Connect to the command created event.
        sampleCommandCreated = SampleCommandCreatedEventHandler()
        buttonSample.commandCreated.add(sampleCommandCreated)
        handlers.append(sampleCommandCreated)
        
        panel = ui.workspaces.itemById('FusionSolidEnvironment').toolbarTabs.itemById('SolidTab').toolbarPanels.add("sashasPanelId","My Panel","SolidCreatePanel",False)
        
        buttonControl = panel.controls.addCommand(buttonSample)
        buttonControl.isPromotedByDefault = True
        buttonControl.isPromoted = True
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# Event handler for the commandCreated event.
class SampleCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
        cmd = eventArgs.command

        # Connect to the execute event.
        onExecute = SampleCommandExecuteHandler()
        cmd.execute.add(onExecute)
        handlers.append(onExecute)


# Event handler for the execute event.
class SampleCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.CommandEventArgs.cast(args)

        reload(my_module)
        my_module.sayHi()
        # Code to react to the event.
        # app = adsk.core.Application.get()
        # type = app.activeDocument.products.itemByProductType('DesignProductType').parentDocument.objectType

        # ui  = app.userInterface
        # ui.messageBox('boo')
        # ui.messageBox('type: {}'.format(type))

def stop(context):
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        # Clean up the UI.
        cmdDef = ui.commandDefinitions.itemById('MyButtonDefIdPython')
        if cmdDef:
            cmdDef.deleteMe()
            
        myPanel = ui.allToolbarPanels.itemById('sashasPanelId')
        
        cntrl = myPanel.controls.itemById('MyButtonDefIdPython')
        if cntrl:
            cntrl.deleteMe()

        if myPanel:
            myPanel.deleteMe()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))	
0 Likes
Accepted solutions (1)
261 Views
2 Replies
Replies (2)
Message 2 of 3

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

Your code is correct and it produces the desired result as you can see in the following image:

Jorge_Jaramillo_0-1728237345140.png

 

It was tested under the following versions:

Fusion:app.version='2.0.20460'

Python:sys.version='3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]'

 

Can you share an image on how it looks on your site?

 

Regards,

Jorge

 

0 Likes
Message 3 of 3

soswow
Advocate
Advocate

hm. Thx @Jorge_Jaramillo after restarting it works correctly now.