MoI discussion forum
MoI discussion forum

Full Version: how to terminate a script

Show messages: All  1-3  4-9

From: Michael Gibson
13 Sep 2022   [#4] In reply to [#3]
Hi Peer,

re:
> First, how can I avoid the infinite loop that results if a script is set to repeat, but the script throws
> an alert and then exits as soon as the alert button is clicked?

That's a bug in that script, it should disable the repeat checkbox which is done by setting:
// config: norepeat
at the top of the .js script file. I've updated the script to have that now so you shouldn't run into this with the updated version.

The repeat checkbox is primarily meant for use with drawing commands and not ones that do selection.

You can still repeat a command that does selection by right clicking in the viewport or pushing the Enter key while in selection mode. If you only need to repeat things sometimes it's easier to use to use right click to do it, the repeat checkbox is for stuff like you're going to draw a whole bunch of points or lines.


> and had to force quit MoI while I had unsaved work on a project that I cared about. Now I'm leary
> of ticking the Repeat checkbox for any script, even though it would be handy to use repeat sometimes.

Sorry you ran into this data loss. If you run into this kind of loop again you can recover your file by triggering a crash.
To do that find the pid for the MoI process in Activity Monitor and from a Terminal prompt do:

kill -s SIGSEGV pid_number_here

That should cause MoI to trigger the crash dialog where you can save your file.


> Second, how can I safely re-prompt a user for input?

I'll take a look at this part in a bit.

- Michael
From: Michael Gibson
13 Sep 2022   [#5] In reply to [#3]
Hi Peer,

re:
> Second, how can I safely re-prompt a user for input? If I run the script below, set the
> CPlane at the wrong orientation, and then hit Esc on the next iteration through the
> While loop it goes into an infite loop. It's like the line moi.View.setCPLaneInteractive();
> is getting skipped over, but the While loop is still running.

What's happening is when you hit Esc or the Cancel button it's trying to cancel the current running command. This sets a "pending cancel command" state.

When moi.view.setCPlaneInteractive() goes into its internal event loop it sees that there is a pending cancel for the current command, and it immediately exits but there isn't a way currently for the script to know about that and so the script continues its while loop. With the next beta where moi.view.setCPlaneInteractive() will return false if it was canceled you can then update this script to have:

code:
	// user picks orientation of new CPlane
	if ( !moi.View.setCPLaneInteractive() )
		break;


If you use the orientation picker directly instead of moi.view.setCPlaneInteractive() you'll have your own event loop and you should be able to see a cancel when picker.waitForEvent() returns false. On the orientation picker you can also call picker.allowNestedCancel() which will then cause Esc or the Cancel button to cancel just that picker's wait instead of doing a full command cancel which is the default behavior.

I'll see about adding in an optional boolean to moi.view.setCPLaneInteractive() so you can set it to do a nested cancel as well.

- Michael
From: pressure (PEER)
14 Sep 2022   [#6] In reply to [#5]
Michael,

Thanks for explaining "// config: norepeat". I saw that at the top of a few scripts and wondered what it was about. What does this do?
// config: norepeat noautolaunch

I guess "// config: norepeat" should be at the top of every script that can create an alert triggered by a problem encountered by the script.

I'll keep your segmentation violation tip in mind in case I'm ever in that pickle again, but hopefully I'll be able to avoid it with everything else you've shared.

I haven't done anything with pickers or event loops yet, but I'll try out your suggestions.
From: Michael Gibson
14 Sep 2022   [#7] In reply to [#6]
Hi Peer,

> What does this do?
> // config: norepeat noautolaunch

The no autolaunch is for when a command set is launched. A "command set" is a group of commands like Draw curve > Lines is a command set that has 2 commands in it (Line, Polyline).

When you open a command set (like click on Draw curve > Lines), the last used command will automatically start unless it's marked with "noautolaunch" which should be set on a command that just does its action immediately like Boolean Union for example.


I think I'll set it up so that if an alert dialog is launched it will automatically clear out the Repeat checkbox to help avoid getting stuck like this.

Thanks,
- Michael
From: pressure (PEER)
14 Sep 2022   [#8] In reply to [#7]
Michael,

Thanks for explaining noautolaunch. I looked at BooleanUnion and Lines.xml and see what you mean. It didn't occur to me that a command set is a thing. Also, it's nice to know that I can repeat a command by hitting Enter. I only knew about right click.

I like your idea of clearing the Repeat checkbox.

Message 10847.9 was deleted


Show messages: All  1-3  4-9