View Full Version : How to implement an Abort button?
04-03-2009, 09:23 PM
I have a script that creates a lot of geometry after entering some parameters and clicking on an execute button.
If it's taking too long, is there a way to stop it so the user can lower the parameters and start again? The idea is to stop the part where the objects are created, not the script itself.
I hope my example is not too confusing. Thanks for your help.
04-03-2009, 09:29 PM
Not via a button, as 3ds Max is going to be far too busy to worry about users clicking buttons.
if (keyboard.escPressed) do ( exit ) -- bail from this loop early, further code will still be executed
04-03-2009, 09:41 PM
Thanks, Richard. That looks even better than using a button.
Do I have to set escapeEnable = false first to prevent the script from crashing?
04-03-2009, 09:48 PM
can't say I've ever had to do that, but might be a good safety precaution
04-03-2009, 11:18 PM
Richard, it works like a charm. Thanks again.:thumbsup:
04-07-2009, 07:22 AM
I don't know if it's still the case, but when I've used that kind of escape hatch with maxscript, it doesn't care if max is active or not. As in if you have a script working in the background and you've popped another app up in the front. Then you hit esc to do something in the app you're working in, it will still stop the script from running in the background. That bit me in the butt a few times with stuff that I was solving with a script in the background while working on other things in other apps.
Just something to keep in mind.
04-07-2009, 07:36 AM
yep - sadly there's no way to check if 3ds Max is the foreground window (maybe with .NET, but got stuck last time I tried) to prevent that. Again, this type of bail-out is mostly when still developing scripts so that if you accidentally created an endless loop, you can exit it without having to end-process max, re-start, potentially having lost script code, etc.
It -can- be used in final scripts, but I would highly recommend you also check for, say, keyboard.shiftPressed. That way users can still end processing but they have to hit the otherwise uncommon keycombo of Shift+Escape. (Ctrl+Escape pops up start menu, Alt+Escape tends to minimize the current app.)
04-07-2009, 08:58 PM
if keyboard.escPressed do DoAbort = queryBox...
If I try
if keyboard.escPressed and keyboard.shiftPressed do DoAbort = queryBox...
it doesn't work.
Is there a special way to deal with keyboard inputs?
04-07-2009, 09:01 PM
a good method for a final script might also be to use a Progress Bar display which will give you both a Cancel Button and the option to ESC cancel, and of course shows you the progress to ease the wait.
NotCancelled = true
progressStart " Testing! "
for i = 1 to 6000 while NotCancelled do
Percentage = 100. * (i / 6000.)
NotCancelled = progressUpdate Percentage
for x = 1 to 5000 while NotCancelled do
y = 2
04-07-2009, 09:16 PM
ho-hum.. what's up with that.. you're right - can't seem to get that to work here either now o_O
I copy/pasted that from an ooooooooold script of mine.. must've worked at some point.
I'm guessing something intercepting the shift+escape (much like ctrl & alt) somewhere.. your guess is as good as mine as to what that might be.
well unless you want to get silly with something like 'mouse cursor must be in upper-left corner of screen when hitting Esc' (mouse.screenpos), I suppose just watching your Esc key pressed would have to do ;)
The .NET way seems to involve writing some C#/something to call the Win32 APIs to get e.g. the foreground window.
04-07-2009, 09:17 PM
one down side to the progress bar (the one in max's status/etc. area) is that it also hides all other dialogs :|
04-07-2009, 09:32 PM
Well, it was a minor thing anyway.
I won't add a progress bar as I already have one in the rollout (and am too lazy to change it).
Here is the final scrip: http://www.scriptspot.com/3ds-max/fracture-voronoi
I don't know if it'll be usefull but I had fun writing it. And learned a ton of things in the process.
04-07-2009, 09:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.