Hi,
I have a question about the current frame and pre-render script.
Basically, I would like to have the output file named by the scene material (VraySwitchMtl), which is animated. So, the output file name would be something like:
“Chair” + <VraySwitchMtl.index[currentFrame]>.
This setup only works for the current frame that is shown in the timeline. I would like to read the current render frame number to achieve full functionality.
Any suggestions would be appreciated.
Thanks.
Tom
If you are referencing the currentTime.frame value, it won't work as expected. This is because currentTime.frame returns the frame that is active on the time slider, and you need the frame number that is currently rendering.
Here is code that I am using as Pre-render script:
mat = sceneMaterials["myMat"] /*Material to get names*/
matNo = (mat.switchNum as integer)
matObj = mat.switchMtl
f = currentTime.frame /*??? want to get frame number that is currently rendering*/
matName = matObj[f+1].name
rendSaveFile = true
fileLoc = "C:/Users/xyz/Desktop/"
fileExt = ".png"
rendOutputFilename = fileLoc + matName + fileExt
Edit:
Found solution to read out which frame number is rendering, but still can't get that value into Pre-render script.
fn myCallback = currentTime.frame as integer
callbacks.addScript #prerenderframe myCallback id:#myCtCallback
The MXS help for "#prerenderframe" says: "The current frame being rendered is set into the MAXScript currentTime context and system global"
I just tried this test and it seems to work correctly:
callbacks.removeScripts id:#myCtCallback
fn myCallback = (
local t = currentTime.frame as integer
format "Rendering frame %\n" t
)
callbacks.addScript #prerenderframe myCallback id:#myCtCallback
Evaluating this code and then rendering either a single frame or a range of frames will print the rendered frame numbers to the listener...
Martin Breidt
http://scripts.breidt.netit sounds like you need only the currently rendering time... so the easiest way to get is:
callbacks.removescripts id:#my_render_monitor
fn on_preRenderEval =
(
t = int (callbacks.notificationParam())
format "frame: %\n" t
)
callbacks.addscript #preRenderEval "on_preRenderEval()" id:#my_render_monitor
just know -
#preRenderEval
is the last render notification, after which you will not be able to change anything in the scene.
Thank you for the responses. They helped me better understand the entire rendering process.
Both methods, #preRenderEval and #prerenderframe, return values as expected.
However, I'm still having trouble saving the image using the rendOutputFilename function.
I can't set name of output file based on the material switch ID.
I tried incorporating the lines of code into the preRenderEval , but without success.
Is it even possible to control rendOutputFilename during the pre-render phases?
Is it even possible to control rendOutputFilename during the pre-render phases?
You might want to consider using the render() method in MAXScript directly - that will return a bitmap which you can save, or it can directly be called with an outputfile: argument with the filename to save to.
Martin Breidt
http://scripts.breidt.netCan't find what you're looking for? Ask the community or share your knowledge.