Get current frame

Get current frame

mislavto_bargra
Observer Observer
1,219 Views
6 Replies
Message 1 of 7

Get current frame

mislavto_bargra
Observer
Observer

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

0 Likes
1,220 Views
6 Replies
Replies (6)
Message 2 of 7

istan
Advisor
Advisor
0 Likes
Message 3 of 7

tgrabar
Explorer
Explorer

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





0 Likes
Message 4 of 7

MartinBeh
Advisor
Advisor

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 B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 5 of 7

denisT.MaxDoctor
Advisor
Advisor

it 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.

0 Likes
Message 6 of 7

tgrabar
Explorer
Explorer

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?

0 Likes
Message 7 of 7

MartinBeh
Advisor
Advisor
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 B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.