Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()))
Solved! Go to Solution.