Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
This is related to the discussion Add-in with Run on Startup enabled crashes Fusion 360 at launch by @BradAndersonJr
Fusion 360 crashes when a palette is created in the run function of an add-in and the Run on Startup is enabled.
Here is an example :
#Author-Jerome Briot
#Description-Track time spent on Fusion 360
import adsk.core, adsk.fusion, traceback
import threading
app = adsk.core.Application.cast(None)
ui = adsk.core.UserInterface.cast(None)
ctrl = adsk.core.CommandControl.cast(None)
handlers = []
thisAddinName = 'bugPaletteDrawing3'
thisAddinVersion = '0.0.0'
thisAddinAuthor = 'Jerome Briot'
thisAddinContact = 'jbtechlab@gmail.com'
# Event handler for the commandExecuted event.
class ShowPaletteCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
palette = ui.palettes.itemById(thisAddinName + 'Palette')
palette.isVisible = not(palette.isVisible)
except:
ui.messageBox('Command executed failed: {}'.format(traceback.format_exc()), thisAddinName, 0, 0)
# Event handler for the commandCreated event.
class ShowPaletteCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
command = args.command
onExecute = ShowPaletteCommandExecuteHandler()
command.execute.add(onExecute)
handlers.append(onExecute)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), thisAddinName, 0, 0)
def run(context):
global ui, app, ctrl
try:
app = adsk.core.Application.get()
ui = app.userInterface
qatRToolbar = ui.toolbars.itemById('QATRight')
showPaletteCmdDef = ui.commandDefinitions.addButtonDefinition(thisAddinName + 'CmdDef', thisAddinName, '', './resources')
# Connect to Command Created event.
onCommandCreated = ShowPaletteCommandCreatedHandler()
showPaletteCmdDef.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
ctrl = qatRToolbar.controls.addCommand(showPaletteCmdDef, 'HealthStatusCommand', False)
ui.messageBox('Create palette')
palette = ui.palettes.add(thisAddinName + 'Palette', thisAddinName, 'test.html', True, True, True, 350, 400)
ui.messageBox('OK')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), thisAddinName, 0, 0)
def stop(context):
try:
cmdDef = ui.commandDefinitions.itemById(thisAddinName + 'CmdDef')
if cmdDef:
cmdDef.deleteMe()
qatRToolbar = ui.toolbars.itemById('QATRight')
cmd = qatRToolbar.controls.itemById(thisAddinName + 'CmdDef')
if cmd:
cmd.deleteMe()
palette = ui.palettes.itemById(thisAddinName + 'Palette')
if palette:
palette.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), thisAddinName, 0, 0)
Thank you
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Solved! Go to Solution.