Notifications
Clear all

[Closed] cancel loop?

hi, my first post here – and beware, i am real new to the realm of maxscript…

i’ve managed to write a script that selects objects from a scene according to object length/width/height. all is fine, except that when i hit that scene with 40.000 objects, it obviously takes a long time for max to run through the selection loop and it would be real nice to be able to cancel the loop while it is running…problem is, that while the loop is running i have found no way to interrupt it, not even with the escape key… (by the way, i am using a for loop)

…any ideas on how to go about this?

5 Replies

hi,

you could use the progress bar to interrupt long processes. look for the topic “Progress Bar Display” in the maxscript help for details about how to go about doing that.
with that said, I think that doing what you want shouldn’t take that long, even with 40,000 objects, if you post your code someone here might be able to suggest ways to optimize it. in any case, I suggest you also read the topic “How To Make It Faster” in the maxscript help.

hOpe this helps,
o

ahh, nice, there’s two different progressbar’s…i used the other ‘item’ kind of bar which has no cancel options, this one has – and it works too! thanks ofer_z

there’s only one thing, after having clicked ‘cancel’, i am prompted to click ‘yes’ twice, why is that? got something to do with maxscript always returning the final value of the loop? is there a way around this?

here’s my loop:

numObjs = 1000
progressStart “Creating Objects…”
for i = 1 to numObjs do
(
if (getProgressCancel()) == true then exit
progressUpdate(100.*i/numObjs)

myObj = box length:20 width:20 height:20

)
progressEnd()

1 Reply
(@ofer_z)
Joined: 11 months ago

Posts: 0

the reason for that is that progressUpdate is also used to check if the cancel button was pressed, so in fact you are checking twice for the cancelation. the reason for getProgressCancel is that it uses less resources, and in very large and intensive loops you may want to allow the user to abort even in parts where you don’t update the progress bar.

anyway, check this out, this solves your problem:


 numObjs = 1000
 progressStart "Creating Objects..."
 for i = 1 to numObjs do
 (
 	if not (progressUpdate(100.*i/numObjs)) then exit
 	
 	myObj = box length:20 width:20 height:20
 )
 progressEnd()
 

hOpe this helps,
o

Be very careful with the progress bar. I chased a bug with a script for about 3 days and it came down to the fact you were unable to switch to ‘edit’ mode from ‘create’ mode with a progress bar active. Something wrong with how max locks the ui with the bar active. If you need to access any modifier information out of a skin (which requires you to be in edit mode with that specific skin modifier active (skinops) – a real big flaw with max’s skin modifier btw) then you can’t use a progress bar.

I’ve actually written my own progress bar that’s just as efficient as max’s except not as nasty – I might post it at some point.

However in regards to your first question try this instead?


  escapeEnable = true;
  
  <your code>

ah, yes of course, should have spotted that one, says quite clearly in the help file that both commands checks the cancel button, thanks for pointing it out and for a good solution ofer_z!

and thanks for the warning impus, always good to be aware of lurking bugs, post your progressbar if you can find the time, would be nice to see how you did that one

as for the escapeEnable = true, i already tried that one in


on selObjsNum open do
(
      escapeEnable = true
)

but it only seems to work together with a progressbar?! hmm, at least things are working kind of smooth now, just got to get this noodlecode optimized…thanks for all the help!