progress ESC

How do I make it so when the user hits the ESC key the operation is completely stopped and canceled....
I've been trying to trouble shoot this and the help file is not really explaining it well enough in a way that is making sense.

Thanks

John

startFrame = animationRange.start
endFrame = animationRange.end
frameCount = endFrame - startFrame
step = 1
prgCount = 0
 
progressStart "Go:"
for t = startFrame to endFrame by step do
(
	if keyboard.escPressed then
	exit with (escapeEnable = false; progressEnd(); format "Canceled\n")
	else (
		sliderTime = t
 
		progPerct = (100.0 * prgCount * step / frameCount) as integer --//ProgressValue
		progressUpdate progPerct
		prgCount += 1
	)
)
progressEnd()

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

I have implemented what you

I have implemented what you have written but once I uncomment the

progressStart "Go:"
progressUpdate progPerct
progressEnd()

And run the script I continualy get this "Question" dialog which pops up and whether i hit yes or no it still runs the for loop.....hmmm?

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

Yeah, the PBar is very

Yeah, the PBar is very capricious feature :)
I remember that changing escapeEnable not help,
and the ESC key messed up with the PBar cancelation.

The fix is to use other key than ESC, Ctrl for example.
Also sometime needs to set progressUpdate 100.

In other words, replace last lines:

stop = keyboard.controlPressed
)
progressEnd()

with:

stop = keyboard.controlPressed
)
progressUpdate 100
progressEnd()

my recent MAXScripts RSS (archive here)

Anubis's picture

An easy made logical mistake,

An easy made logical mistake, I think. Your Exit break only stop the progressbar but not the for-loop. You can fix that with boolean pointer into the for-loop (using while), something like:

startFrame = animationRange.start
endFrame = animationRange.end
step = 0.1
 
frameCount = (endFrame - startFrame + 1) / step
-----------
prgCount = 0
stop = false -----------
progPerct = 0
 
progressStart "Go:"
for t = startFrame to endFrame by step while not stop do
(
	sliderTime = t
	--format "I'm at frame: %\n" t
 
	prgCount += 1
	progPerct = (100.0 * prgCount * step / frameCount) as integer
	progressUpdate progPerct
 
	stop = keyboard.escPressed -----------
)
progressEnd()
 
if prgCount < frameCount do
	format "Canceled at frame: %\n" sliderTime
format "Progress done: %\%\n" progPerct

my recent MAXScripts RSS (archive here)

JokerMartini's picture

MZP

they are un-readable files?

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

miauu's picture

I don't have time to find out

I don't have time to find out and post the code, but download RTTAssist and check EXPLODE function. You can see haw I use ESC key to stop explosion.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.