Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get current frame

6 REPLIES 6
Reply
Message 1 of 7
mislavto_bargra
496 Views, 6 Replies

Get current frame

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

6 REPLIES 6
Message 2 of 7
istan
in reply to: mislavto_bargra
Message 3 of 7
tgrabar
in reply to: mislavto_bargra

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





Message 4 of 7
MartinBeh
in reply to: mislavto_bargra

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

EESignature

→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 5 of 7

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.

Message 6 of 7
tgrabar
in reply to: mislavto_bargra

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?

Message 7 of 7
MartinBeh
in reply to: tgrabar

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

EESignature

→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report