Notifications
Clear all

[Closed] Can anyone help me cancel this script?

Hi there,

I am making a script that will process objects throughout the length of an animation, but I can’t seem to cancel the script once it’s running
It seems that whenever you are messing with the slidertime it takes over all control of max.

I put together a quick script to demonstrate the issue, if you have a sec, run it and see if you can cancel (or do anything for that matter!).


rollout progressTest "Progress Test"
(

	button ProcessScene "Process Scene" across:2 -- START Button
	button cancelIt "Cancel Scene" -- CANCEL Button

	progressbar ProcessScene_prog color:red -- Progress bar
		
	local	cancelNow = false
		
	on ProcessScene pressed do (
	cancelNow = false
	previewLength = (0 - 80)
	AnimLength = (animationrange.end - animationrange.start)
	CurrentF = 0.0
	TestVal = 0.0
	for t = animationrange.start to animationrange.end do
		(
			if (cancelNow == true)then(
				print ("Cancel")
				return()
			)
		sliderTime = t
		TestVal = (CurrentF/AnimLength)
		ProcessScene_prog.value = (TestVal * 100.0)
		CurrentF += 1.0
		)	
	ProcessScene_prog.value = 0 -- when ready, reset the progress bar to 0%
	)

	on cancelIt pressed do (
		cancelNow = true
		print ("Cancel Pressed")
	)
	
)

createDialog progressTest 200 60 -- create a dialog to test 

Any ideas on how to get that cancel button working?
Thanks,
Pete

2 Replies
 lo1

functions run synchronously, which means your UI is not accessible while your code is running.

two options:

  1. use progressStart and progressEnd. This will let you use max’s cancel button.
  2. check for keyboard.escPressed on every iterations instead of your cancel flag.

Hey Io
I had the same trouble with use progressStart and progressEnd but checking for keyboard.escPressed worked great,
Thanks!
Pete