Run on startup - AddIn problem

echatzief
Advocate

Run on startup - AddIn problem

echatzief
Advocate
Advocate

Hi forum,

I'm trying automatically run an a script, when fusion 360 launches, making use of the so called addIn.

The problem is that :

When I am debugging my addIn through fusion 360 scripts&addIns tab, everything works fine, meaning my addIn is running properly, generating the desired outcomes.

When I'm openning fusion 360, the addIn is also running, though it is being stuck when I'm creating the first operation to my manufacturing design. So the problem is the run on startup feature, cause the results are not the anticipated ones. I am also getting a Fusion 360 error - access violation (c0000005).

If you have any tips in mind, I would really appreciate it if you let me know!

Thank you in advance!

1 Like
Reply
1,479 Views
13 Replies
Replies (13)

kandennti
Mentor
Mentor

Hi @echatzief .

 

I think the reason for the error is that the process is executed too early.

 

I used this add-in to make the palette appear when Fusion360 is started.

https://github.com/kantoku-code/Fusion360_Developers_Small_ToolKit 

 

The event I used is the UserInterface.workspaceActivated event.
And once the event occurs, I delete the handler that was registered.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fcb72832-b3bb-4a12-b590-977e75e915ca 

 

The add-in over there is very voluminous, so I have created a minimal add-in and attached it for you to try.
The 'Hello World' dialog is displayed when an event occurs.
However, the timing of the event is here.

1.png

 

Depending on what you are processing, you may need to combine other events.

1 Like

echatzief
Advocate
Advocate

The problem is NOT solved!

I have tried everything, but I am not able to create any operations to my setups, when the add-in is running on startup. I have also included event handlers to my code, but nothing has been accomplished yet!

@BrianEkinsWhat are your thoughts on this? I have tried "createFromTemplate", "createFromCamTemplate", and "createInput" methods, in order to find a way to create operations to my runOnStartup-addIn. I am able to run my addIn, when it is not running on startup. 

1 Like

Jorge_Jaramillo
Collaborator
Collaborator

Hi @echatzief ,

Had you ever try a custom event to start the operations in you addin?

I'd used it in some situations where the operation needs to be executed later on other thread apart from the current that is taking care of the system event.

 

0 Likes

BrianEkins
Mentor
Mentor

I agree with the previous comments that you are trying to do something too early. When add-ins are being loaded, Fusion is still in the process of starting up. The only thing you should do in the run method of your add-in is to add buttons to the UI and connect to events. The Application.startupCompleted event is fired once Fusion has completed the start-up tasks.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

echatzief
Advocate
Advocate

Hi all, thank you for your responses!

I have tried using the startupCompleted event, executing my desired methods after the event is fired, but it seems that it nevers completes it's initialization. I have not tried sending an event to the worker thread back to my addIn on the main thread. Any tips on this?

Thank you!

0 Likes

kandennti
Mentor
Mentor

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.

1 Like

echatzief
Advocate
Advocate

Hello @kandennti thanks for your reply.

I am getting something like this :

DocumentCreated

DocumentActivating

OnWorkspaceActivated

OnCommandTerminated

OnCommandTerminated

OnCommandTerminated

OnCommandTerminated

OnWorkspaceActivated

OnCommandTerminated

StartupCompleted

OnCommandTerminated

 

In my case, the startupcompleted event is fired at the very end. This seems like a BUG to me, I have tried using each event seperately, or even combining them, but I cannot manage to get my addIn work. Anyone having any suggestions would be much appreciated.

Thank you again @kandennti .

 

2 Likes

echatzief
Advocate
Advocate

I have tested my code on other pc's too, the problem does not has to do with my pc.

When I'm adding the startup completed event, I can't get to print/messageBox anyting inside the handler (if I'm creating operations to my setups), because fusion crashes. When I'm not creating operations nothing goes wrong. I am eagerly looking forward for a solution here.

I have spent a lot of time on this, without concluding to any solutions, anyone having any thoughts will be much appreciated. @Jorge_Jaramillo do you have an example?

@BrianEkinsCould you please be more specific?

Thank you again

1 Like

kandennti
Mentor
Mentor

@echatzief .

 

The attached add-in uses threads to create a manufacturing setup and import a Step file at startup.
In a new document, I could not create a new setup this way.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/feature-request-create-setups/m-p/11849662... 

 

I am not sure why, but if I had only one setup in an empty document, I could create it, so I imported the previously created document and imported the Step file as well.

 

I imported the template and tried to run the calculations, but Fusion360 crashed. (Ver 2.0.15509)

 

This is as far as I can help. I look forward to hearing back from you with good results.

 

0 Likes

kandennti
Mentor
Mentor

I noticed that the documentation is publicly available.
I used Insider (Ver. 2.0.15775) and combined it with this sample.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c4836048-974e-4544-acc0-d384e7e55613 

 

At startup, the creation of the setup and the creation of the operation succeeds, but,
When I run the generateToolpath method to calculate the toolpath,
Fusion360 crashes.

Running the sample script after Fusion360 starts works fine.

 

0 Likes

echatzief
Advocate
Advocate

Hi @kandennti thanks for your reply.

The dll file that crashes is IronCore10.dll

The log file coming with fusion when it crashes is the following:

 

"""

(module:IronCore10) File: (filename not available): Iron::FeatureFlag::getFeatureFlagLogInfo
(module:IronCore10) File: (filename not available): Iron::IronDocToolpathGenerator::prepareObjectForGeneration
(module:IronCore10) File: (filename not available): Iron::IronDocToolpathGenerator::generateToolpath
(module:IronCore10) File: (filename not available): Iron::IronDocument::generateToolpath
(module:IronCore10) File: (filename not available): Iron::IronDocument::generateToolpath
(module:NaNeuCAM10) File: (filename not available): IronServer::IronDocumentEntity::onObjectCreated
(module:IronCore10) File: (filename not available): Iron::IronDocument::applyObjectChange
(module:IronCore10) File: (filename not available): Iron::OperationTemplate::createOperation
(module:IronCore10) File: (filename not available): Iron::CreateFromTemplateRequest::onExecute

"""

1 Like

kandennti
Mentor
Mentor

If I run Fusion360 while starting it up, it crashes, but if I run it after startup, it runs correctly without crashing.
Perhaps it is a timing issue and not a bug.

0 Likes

echatzief
Advocate
Advocate

Hi @kandennti 

It is indeed a timing issue, but startup completed event handler never gets executed. So there is nothing I can do to know when fusion initializes, hence my assumption that it is a bug.

 

0 Likes