Notifications
Clear all

[Closed] Interrupting and/or pausing batch render script

Hi guys,

I’ve been working on a script that creates sprites from a certain cameraview. The script rotates the camera so that it describes a spherical path around the object.

It renders anywhere between 20 and 800 frames. Each time a frame is completed, a couple of things change, and the camera is rotated before it starts rendering the next frame.
When all is done, the images are passed on to a script I wrote that stitches everything together.

I’ve got everything working nicely, except for one thing: controlling the rendering process.
When you’ve got say 400 frames to render, with GI, DoF and what not, you definitely want to be able to cancel the rendering process. And what’s more, I want to be able to do it decently. Pushing the escape key for a couple of seconds basically does the trick, but it throws up some script errors (because of ‘missing’ data later on in the script, due to the aborted loops) and eventually max crashes.
I have written a resume function, so theoratically aborting a render this way doesn’t do much harm, but it’s not a very charming way.

I have quite literally been searching for days on how to accomplish this, but I can’t seem to find anything useful.
One thing I tried is making a button (as you can see in the rendering screen), that will change a variable which is being evaluated with each loop iteration. That should -in theory- be enough to at least break off the loops (the current frame render will still continue though). But the irony is, that when rendering, max seems to be too busy to respond to the button…

I hope that some of you guys can help me with this issue. Any thoughts, ideas and opinions on it are very much appreciated.
Thanks in advance!

Oh by the way, I think that it’d be good to mention: my experience with maxscript is rather limited, I’ve only started using it a week ago. But I do have quite some experience with other scripting and programming languages, like php, actionscript, java etc.

6 Replies

If you are rendering by calling the render() method, you shoud use the built-in cancel mechanism as documented in the Reference.

The render() method provides an optional parameter Cancelled: where you can pass a by-reference variable which will contain true if you pressed Esc while rendering or false if not. You can then use an IF statement right after the render() call to see if the user pressed Esc and exit the loop if requested.

Before you call render(), make sure you have disabled cancel handling for scripts (it is disabled in Max 9 by default anyway) by setting escapeEnable=false so pressing Esc does not break your own code but only stops the renderer. If you want, you could set escapeEnable=true after exiting the loop.

How in the world could I have missed that? I’ve literally been reading and searching through the reference for hours, but I just missed it.

Is it correct that you can only cancel the render() function by pressing the escape key? Or is there some other way to do it, or perhaps even fake the ‘escape pressed’ ?
I’m using max7 by the way.

Thanks for your help!

you could use
if (keyboard.escPressed == true) do
and a return command or
while (keyboard.escPressed != true) for your loop.

cleaning up the scene (temp objects, etc.) will have to be
outside your loop then, or invoke it by checking the
return value for if it was escaped.

I see, but the point is, I’d like to have a cancel button, rather than the ability to cancel the process by pushing escape. That’d be somewhat more userfriendly.

either i´m not really getting the point or couldn´t you just check for the
pressed state of your cancel button then? and use a return or use it as
a “while” with your loop? i´m not sure how to also cancel the renderer using
that button but it should be able to break your other code using that.

Yeah I’ve now got it set up like this: (a bit simplified of course)


     global renderAborted = false;
     
     function startRender = (
       for h = settings.hStepsCompleted to settings.hSteps do (
     	  if renderAborted then (
     		 exit();
    	  ) else (
     
     		 for v = settings.vStepsCompleted to settings.vSteps do (
  			if renderAborted then (
     			     exit();
     			) else (
     				--render.
     			)
     		)
     
     	)
          )
    )

edit: sorry for the crappy formatting…

 And then theres a button somewhere that can change the state of renderAborted to true.
 The thing is, this does not cancel the current frame. Another problem is that in some cases (this time with other operations than rendering, for example the stitching of bitmaps), the button does not respond to any clicking at all, probably because max is so busy doing the stuff that should be cancelled...