Add-in with Run on Startup enabled crashes Fusion 360 at launch.

Add-in with Run on Startup enabled crashes Fusion 360 at launch.

BradAndersonJr
Enthusiast Enthusiast
1,105 Views
3 Replies
Message 1 of 4

Add-in with Run on Startup enabled crashes Fusion 360 at launch.

BradAndersonJr
Enthusiast
Enthusiast

Greetings!

 

I recently put together a fun, little add-in that produces a simple conversion chart for fractions/decimals/millimeters.  I've come across an issue though, when I try to enable the add-in to Run on Startup Fusion 360 fails to load and gives me the crash report prompt.  The add-in utilizes a QAT Toolbar and I'm not sure if that's what the issue is or not, everything else seems sound but then again I'm fairly novice at python still.

 

Here's the .py file:

#Author-Brad Anderson Jr
#Description-Conversion Chart

import adsk.core, adsk.fusion, traceback

app = adsk.core.Application.cast(None)
ui = adsk.core.UserInterface.cast(None)
palette = adsk.core.Palette.cast(None)
ctrl = adsk.core.CommandControl.cast(None)

handlers = []

conversionChartName = 'Conversion Chart'
conversionChartVersion = '1.0'
conversionChartAuthor = 'Brad Anderson Jr'
conversionChartContact = 'brad@bradandersonjr.dev'

# Event handler for the commandExecuted event.
class ShowPaletteCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        global palette, ui
        try:

            cmdDef = ui.commandDefinitions.itemById('showConversionChart')
            if palette.isVisible:
                palette.isVisible = False
                ctrl.commandDefinition.name = 'Show Conversion Chart'
                cmdDef.name = 'Show Conversion Chart'
            else:
                palette.isVisible = True
                ctrl.commandDefinition.name = 'Hide Conversion Chart'
                cmdDef.name = 'Hide Conversion Chart'

        except:
            ui.messageBox('Command executed failed: {}'.format(traceback.format_exc()), conversionChartName, 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()), conversionChartName, 0, 0)

def run(context):

    global ui, app, palette, ctrl
    global process

    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        qatRToolbar = ui.toolbars.itemById('QATRight')

        showPaletteCmdDef = ui.commandDefinitions.addButtonDefinition('showConversionChart', 'Show Conversion Chart', 'Display a conversion chart for fractions, decimals, and millimeters in Fusion 360.', './resources')

        # Connect to Command Created event.
        onCommandCreated = ShowPaletteCommandCreatedHandler()
        showPaletteCmdDef.commandCreated.add(onCommandCreated)
        handlers.append(onCommandCreated)

        ctrl = qatRToolbar.controls.addCommand(showPaletteCmdDef, 'HealthStatusCommand', False)

        palette = ui.palettes.add('ConversionChartPalette', 'Conversion Chart', 'chart.html', False, True, False, 800, 980)
        palette.isVisible = False
        
        # Dock the palette to the right side of Fusion window.
        palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateRight
        palette.dockingOptions = adsk.core.PaletteDockingOptions.PaletteDockOptionsToVerticalOnly(True)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), this_addin_name, 0, 0)


def stop(context):

    global palette

    try:

        cmdDef = ui.commandDefinitions.itemById('showConversionChart')
        if cmdDef:
            cmdDef.deleteMe()

        qatRToolbar = ui.toolbars.itemById('QATRight')
        cmd = qatRToolbar.controls.itemById('showConversionChart')
        if cmd:
            cmd.deleteMe()

        palette = ui.palettes.itemById('ConversionChartPalette')
        if palette:
            palette.deleteMe()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), conversionChartName, 0, 0)

 

Here's the actual GitHub repo: https://github.com/BradAndersonJr/Fusion360-Conversion-Chart

Thanks, 

Brad Anderson Jr

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes
Accepted solutions (2)
1,106 Views
3 Replies
Replies (3)
Message 2 of 4

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

I didn't find yet why Fusion 360 crashes at startup but there are two typos in the code.

 

First, replace

 

palette.dockingOptions = adsk.core.PaletteDockingOptions.PaletteDockOptionsToVerticalOnly(True)

 

With

 

palette.dockingOptions = adsk.core.PaletteDockingOptions.PaletteDockOptionsToVerticalOnly

 

 Next, replace

 

ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), this_addin_name, 0, 0)

 

With

 

ui.messageBox('Failed:\n{}'.format(traceback.format_exc()), conversionChartName, 0, 0)

 

 

 

Message 3 of 4

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

Bug found. This is caused by the creation of the palette.

 

The palette must be created in the ShowPaletteCommandExecuteHandler function and not in the run function.

See the sample code provided by Autodesk: Palette Sample API Sample

 

Comment the lines related to the palette in the run function of your code and Fusion 360 will start with no problem.

 

I will report this bug in a new discussion.

 

Thank you

Message 4 of 4

BradAndersonJr
Enthusiast
Enthusiast

Hey!

 

Sorry for the late response but thank you very much @JeromeBriot!  I followed your guidance and was able to get the add-in to properly work!

 

Thank you!

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes