how to terminate a script
All  1-4  5-9

Previous
Next
 From:  Michael Gibson
10847.5 In reply to 10847.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10847.6 In reply to 10847.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.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10847.7 In reply to 10847.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
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10847.8 In reply to 10847.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.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Message 10847.9 deleted 24 Feb 2023 by MICHAEL GIBSON
 

Reply to All Reply to All

 

 
 
Show messages: All  1-4  5-9