After looking at the documentation link, this is what I came up with. Doesn't work.
I'm hoping it is just the execFile('SHCS') part that is not working.
Can't find how to run another script from a script.
import adsk.core, adsk.fusion, adsk.cam, traceback
handlers = []
def run(context😞
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
addins = adsk.core.ToolbarPanel.cast(ui.allToolbarPanels.itemById("SolidScriptsAddinsPanel"))
dropDown = addins.controls.addDropDown("DropDown", "./Resources")
shcsButton = ui.commandDefinitions.addButtonDefinition("shcs", "SHCS", "Create a SHCS", "./Resources")
fhscsButton = ui.commandDefinitions.addButtonDefinition("fhscs", "FHSCS", "Create a FHSCS", "./Resources")
# Connect to the command created event.
shcsCreated = ShcsCreatedEventHandler()
shcsButton.commandCreated.add(shcsCreated)
handlers.append(shcsCreated)
fhscsCreated = FhscsCreatedEventHandler()
fhscsButton.commandCreated.add(fhscsCreated)
handlers.append(fhscsCreated)
# Get the ADD-INS panel in the model workspace.
addInsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
# Add the button to the bottom of the panel.
dropDown.controls.addCommand(shcsButton)
dropDown.controls.addCommand(fhscsButton)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the shcsCreated event.
class ShcsCreatedEventHandler(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 = ShcsExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# Event handler for the shcs execute event.
class ShcsExecuteHandler(adsk.core.CommandEventHandler😞
def __init__(self😞
super().__init__()
def notify(self, args😞
eventArgs = adsk.core.CommandEventArgs.cast(args)
# Code to react to the event.
app = adsk.core.Application.get()
ui = app.userInterface
execFile('SHCS.py')
# Event handler for the fhscsCreated event.
class FhscsCreatedEventHandler(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 = FhscsExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# Event handler for the fhscs execute event.
class FhscsExecuteHandler(adsk.core.CommandEventHandler😞
def __init__(self😞
super().__init__()
def notify(self, args😞
eventArgs = adsk.core.CommandEventArgs.cast(args)
# Code to react to the event.
app = adsk.core.Application.get()
ui = app.userInterface
execFile('FHSCS.py')
def stop(context😞
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Clean up the UI.
cmdDef0 = ui.commandDefinitions.itemById('shcs')
if cmdDef0:
cmdDef0.deleteMe()
addinsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl0 = addinsPanel.controls.itemById('shcs')
if cntrl0:
cntrl0.deleteMe()
cmdDef1 = ui.commandDefinitions.itemById('fhscs')
if cmdDef1:
cmdDef1.deleteMe()
addinsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl1 = addinsPanel.controls.itemById('fhscs')
if cntrl1:
cntrl1.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))