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: 

ABORT ! ABORT !

6 REPLIES 6
Reply
Message 1 of 7
RogerInHawaii
820 Views, 6 Replies

ABORT ! ABORT !

You can start up a script  via the "Add-Ins->Script and Add-Ins" menu option which gives you a dialog...

abort.jpg

 

from which you can start up a selected script using the Run button or just by double clicking on the script you want to start. There's also a Stop button which apparently is intended to allow you to stop a script. But as soon as you start your script that dialog disappears.

So, how can you stop a running script?

Now, in my particular script I've got a lot of diagnostic messages that pop up via the ui->messageBox() method, and I'm wondering if maybe the popping up of a messageBox is what causes the disappearance of the "Scripts and Add-In" dialog. But still, for a script that's popping up messageBox dialogs, how do I get the script to Stop?

6 REPLIES 6
Message 2 of 7
BrianEkins
in reply to: RogerInHawaii

The Stop button is for add-ins.  When they're started they continue to run in the background until they're stopped or Fusion is shut down.  Scripts run and they're done so there's no need to stop them.

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

Well, no. It's very possible that you have a script that does a whole lot of things and you may need or wish to stop them before they've done everything they were supposed to do. It could be that they're behaving in a way that you hadn't intended or that it's just taking way too long to finish. A script is a program like any other program. There absolutely can be situations where you need to manually stop them. The only way that I've found to stop one (before it's finished) is to close Fusion 360 itself, and that's just not a reasonable way to handle the situation.

 

Message 4 of 7
BrianEkins
in reply to: RogerInHawaii

All API programs, scripts and add-ins, run in the main thread, which is the same thread the UI is running in. When you start a script it has essentially taken over Fusion and you can't interact with the UI unless you call UI specific functions like message or selectEntity, but you can't interact the usual way with Fusion until your script finishes which turns control back to Fusion.

 

An add-in is different because it's started when Fusion loads and then sits running in the background waiting for an event from Fusion but when it's reacting to the event, it's like a script and takes over Fusion until it's execution finishes.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 7
RogerInHawaii
in reply to: BrianEkins

Then why, when the Scripts tab is selected on the "Scripts and Add-Ins" dialog, does the "Stop" button even appear? It certainly gives the impression that it will be enabled and available once a script is started running? If it's not applicable to scripts it simply shouldn't be shown when you're looking at the scripts tab.

Plus, there are other times when the user can start something "running" and there's a way to stop it. You can right click on a Joint and select to either Animate Joint or Animate Model and when it starts moving you can (in fact HAVE TO) hit the escape key to stop it. It would seem reasonable that something similar would be available for running scripts.

Message 6 of 7
BrianEkins
in reply to: RogerInHawaii

It is possible to add some code to a script so that it doesn't automatically stop, essentially turning it into an add-in.  So in these rare cases, the stop button is applicable, but I agree and it would be better if it just didn't show up for the scripts tab.  It wasn't something we thought about at the time.

 

What you're talking about isn't just an issue with Fusion and scripts but is a hard problem to solve in general when writing a program.  For example, if I write a program in C++ that consists of a single function, it's going to run to completion without any opportunity to stop it.  If I want to give the user the ability to stop, it then I need to add code into the function to periodically check if the user has done whatever they need to do to indicate they want it to stop. Then the function would clean up whatever it needs to and return.  As part of that, I need to provide some type of UI to allow the user to signal a stop.  This would end up just setting a flag that the function would look for to know if it should abort.  To make this work I need to either have two thread running (one for the UI and one for the program) or use one thread but in the program, periodically give control back to the UI to allow the user to signal the stop.

 

There isn't a simple way to stop a program from running other than kill the process.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 7 of 7

Aloha Mr. RogerInHawaii,

 

If you want to control your script running  duration consider reading the documentation concerning 

ProgressDialog Object

You will find that adopting your own internal script run-time control is SIMPLE !

 

Regards

MichaelT

MichaelT

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