Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Aborting a script execution

3 REPLIES 3
Reply
Message 1 of 4
TRIALCAD2014
193 Views, 3 Replies

Aborting a script execution

I'm trying to abort further execution of a script using the API.

I tried 

ui.terminateActiveCommand()
but the script keeps executing so that does not work.
plain return works only in the outermost method but not in nested calls.
Normally this would be something like exit(-77) or abort()
I could not find anything in the documentation.
 
Thank you,
Adrian
3 REPLIES 3
Message 2 of 4
BrianEkins
in reply to: TRIALCAD2014

With the way Fusion uses Python, your program is sharing an instance of Python with all of the other programs running. This means you can't terminate Python but instead your program will need to complete its execution.

 

You can add logic that will cause it to terminate earlier but it is logic you'll need to add.  There are different ways to approach this. For example, all of your functions can return whether they were successful or not and the calling code can check the return and determine if it should continue or also return a failure code. These would percolate to the top where you can return from the original function.

 

You can also use a try except statement in the top-level function and then any time you want to abort you can raise an exception which will result in the except statement being called and you can clean up and return.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 4
TRIALCAD2014
in reply to: BrianEkins

Thank you for the reply. I suspected that.

The percolate is cumbersome and error-prone because it's easy to miss
some conditional things or exceptions and it adds a lot of code.

Using exceptions to implement exit functionality is also problematic
both at the code maturity level and also hard to control when it comes
to handling legitimate exceptions.

What is   ui.terminateActiveCommand() good for? I was under the
impression that scripts are implemented as commands so terminating the
command should terminate the scripts.

Message 4 of 4

I've never used it so I may be wrong but ui.terminateActiveCommand terminates the active command that you can get with ui.activeCommand. The command here is the activation of a commandDefinition, it is what is launched when clicking on a button. Ie you click on extrude, the command Dialog is here, you terminate it and it dissapears.

 

As @BrianEkins said, you're better off simply terminating your program if you want to stop.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report