Brian,
This worked well for me. Thank you. I've posted a code snippet for anyone else trying to do this.
Eric
#globals
#these are used in the run and stop functions
butName = 'Mushroom Tray Layout Calculator' #choose a unique id for the button
eco_Tab = 'ecoTab'
eco_Tab_Name = 'Eco Add-Ins'
eco_Panel = 'ecoTrayPanel'
eco_Panel_Name = 'Tray Design Add-In'
controlName = 'TrayLayoutControl' #choose a unique id for the control
butDialogName = 'Tray Layout Dialog' #choose a name for the button
tooltip = 'Auto Create Nested Tray Layout from Cushion Shape' #create a tooltip for the button when someone hovers over it
folderName = 'resources' #create a folder in the directory to hold the icon files and put it's name here
def run(context):
"""The run function is the main function that runs first when loading the Add-in.
It will add a toolbar button to the ui which will be controlled by the comPressedEventHandler class functions."""
ui = None
global units
try:
#get the application
app = adsk.core.Application.get()
ui = app.userInterface
#Get command definitions & design workspace##################################################################################################
cmd_def = ui.commandDefinitions
des_wp = ui.workspaces.itemById('FusionSolidEnvironment')
# Add the Eco Tab to the Workspace.
eco_tab = des_wp.toolbarTabs.itemById(eco_Tab)
if not eco_tab:
eco_tab = des_wp.toolbarTabs.add(eco_Tab, eco_Tab_Name)
# Add the Tray Design panel.
addin_panel = eco_tab.toolbarPanels.itemById(eco_Panel)
if not addin_panel:
addin_panel = eco_tab.toolbarPanels.add(eco_Panel, eco_Panel_Name,eco_tab.id, False)
#Get command definitions & design workspace##################################################################################################
#Add a button CommandDefininition to that collection
# folder name (within same directory) for icons 16X16, 32X32 & 64X64.png) (change button properties in global variables on top)
ret = readConstants("RevisionNumber.txt")
comDef = cmd_def.itemById(butName)
if not comDef:
comDef = cmd_def.addButtonDefinition(butName,
butDialogName + " Rev " + ret[0][1],
tooltip,
folderName)
#Grabbing the correct toolbar panel to add the button to
addinsToolbarPanel = addin_panel
#Adding the button to the toolbar Panel
comControl = addinsToolbarPanel.controls.addCommand(comDef,controlName)
#Making the button visible without having to use the dropdown
comControl.isPromotedByDefault = True
#Setting up the handler if the button is pressed
#Calling the class
comPressed = comPressedEventHandler()
comDef.commandCreated.add(comPressed)
handlers.append(comPressed)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))