This is a meaningless add-in, but if you create this code as an add-in, check the "Run on Startup" checkbox, and start Fusion360, you can see the order in which events occur. The only condition is that you do not perform any operations.
# Fusion360API Python addin
import traceback
import adsk.core as core
handlers = []
def run(context):
try:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
global handlers
workspaceHandler = MyWorkspaceHandler()
handlers.append(workspaceHandler)
ui.workspaceActivated.add(workspaceHandler)
commandHandler = MyCommandHandler()
handlers.append(commandHandler)
ui.commandTerminated.add(commandHandler)
applicationHandler = MyApplicationHandler()
handlers.append(applicationHandler)
app.startupCompleted.add(applicationHandler)
documentHandler = MyDocumentHandler()
handlers.append(documentHandler)
app.documentCreated.add(documentHandler)
app.documentActivating.add(documentHandler)
except:
core.Application.get().log('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
pass
except:
core.Application.get().log('Failed:\n{}'.format(traceback.format_exc()))
class MyDocumentHandler(core.DocumentEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: core.DocumentEventArgs):
core.Application.get().log(f'{args.firingEvent.name}')
class MyApplicationHandler(core.ApplicationEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: core.ApplicationEventArgs):
core.Application.get().log(f'{args.firingEvent.name}')
class MyWorkspaceHandler(core.WorkspaceEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: core.WorkspaceEventArgs):
core.Application.get().log(f'{args.firingEvent.name}')
class MyCommandHandler(core.ApplicationCommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: core.ApplicationCommandEventArgs):
core.Application.get().log(f'{args.firingEvent.name}')
In my environment, the result looks like this
StartupCompleted
DocumentCreated
DocumentActivating
OnWorkspaceActivated
OnCommandTerminated
OnCommandTerminated
OnCommandTerminated
The StartupCompleted event is fired before the DocumentCreated event when a new document is created at startup, and I feel that I cannot do anything with it.
This is why I chose the OnWorkspaceActivated event, because I just couldn't get it to work before.
If you think the slower the better, you might be better off using the OnCommandTerminated event, which is fired the first time.
Perhaps there is a more appropriate event.