Notifications
Clear all

[Closed] Script that repeat itself every frame of a render

Hi I’m really new at script started 2 days ago

I have a hard time with callbacks

I want something to be done every frame of a render just before it renders and then just after but I have a hard time with the callback part how to write it, so what do I need to type if I want this?

Thanx all

17 Replies

here’s a simple script to get you going, it will move a box named “Box01” up 1 unit per frame, then reset it to it’s original position after rendering

callbacks.addScript #preRender "oldBoxPos=$Box01.pos" id:#preRenderStuff
 callbacks.addScript #preRenderFrame "move $Box01 [0,0,1]" id:#preFrameStuff
 callbacks.addScript #postRender "$Box01.pos = oldBoxPos" id:#postRenderStuff

Thanx Aaron this should be very useful, wow I’m starting to understand something

callbacks.removescripts id:#fRGlu
txt = “s = $glu3D_01

txt += “select $s

callbacks.addscript #preRender txt id:#fRGlu
callbacks.addScript #preRenderFrame “snapshot $s” id:#fRGlu
callbacks.addscript #postRender “delete $glu3d_02” id:#fRGlu

I have this so far but I get this error message

>> MAXScript Callback script Exception: – No ““select”” function for undefined <<
>> MAXScript Callback script Exception: – No ““snapShot”” function for undefined <<
>> MAXScript Callback script Exception: – No “delete” function for undefined <<

is there a section in the help that gives more explanation on errors?

the “function for undefined” usually means that the variable the function is trying to access is undefined (has no value)

in your case this is because you’re using dollar sign before your “s” variable… you only use dollar signs to get scene nodes (like you did it with your glu3d object)

Have you checked out the “Learning MAXScript” section of the maxscript reference btw? a lot of this sort of basic stuff is explained in there, and it’s not that long a read… lot’s of stuff will become simple and obvious once you have the basic knowledge. there are updates available to the reference btw, you can get them on the discreet site.

as for your script, i understand you’re trying to make a snapshot of a glu3d system on every frame and delete it after the frame has been rendered.

there’s a couple of things you should change in your script:

  • it’s unnecessary to select the glu3d object
  • use variable names that are self-explanatory, or at least names that you yourself will understand if you look at the script in two months time (“s” doesn’t exactly fall into that category )
  • use postRenderFrame for your cleanup, postRender is executed after the whole render(-sequence) is finished, the way you do it you will have 100 glu3d objects after 0-100 frames, with only glu3d_02 having been deleted
  • use a unique id for each callback

something i forgot to mention: i noticed before that some render callbacks don’t work with vray (and possibly other 3rd party renderers) …beware…

use postRenderFrame for your cleanup, if I do this won’t it delete the object before the render of the frame?

By the way thx for all your tips, oh by the way I’m trying to make this script work asap cause
it’s the only way I can use glu3d with finalRender.

Ok I’m getting close

this one works for one frame but when i do a sequence it crashes on the second frame

callbacks.removescripts id:#fRGlu
txt = “liq = $glu3D_01

txt += “snapshot liq
” –snapshot my Glu mesh
callbacks.addScript #preRender txt id:#fRGlu
txt = “delete $glu3d_02

callbacks.addScript #postRenderFrame txt id:#fRGlu

I tried with a different id for the delete callback but I still crash

one more thing if I do my snapshot with a prerenderframe, nothing appears so I need my snapshot before that

callbacks.removescripts id:#fRGlu
txt = “liq = $glu3D_01

txt += “snapshot liq
” –snapshot my Glu mesh
callbacks.addScript #preRenderFrame txt id:#fRGlu
txt = “delete $glu3d_02

callbacks.addScript #postRenderFrame txt id:#fRGlu

this one doesn’t work for one frame but works for a sequence but my mesh is one frame to late, in other words the mesh that should be on the first frame is on the scond and so on.

please help I need this working asap and i have no idea what I’m doing

Page 1 / 2