[Closed] count frames to render, then output each
Ok, I am stumpted on this one, I need to write some batch code to open a scene, check howmany frames it has been set to (if there is animation) and then render each frame out as a separate file. Basically i cant seem to figure out how to check for frames in the scene.
I was going to try using FrameTagManager, but I do not think its correct.
If you want the scene animation range, you have
animationrange –>returns an interval with start and end
animationrange.start –>returns the start of the interval
animationrange.end –>returns the end of the interval
If you want the Render Scene Dialog settings (which could be different from the scene range), see the Render Scene Dialog topic in the MAXScript Reference for details.
Browsing through the Max Reference I see this
rendTimeType – integer
Get/set the type of time range to be rendered. One of the following values:
1 – A single frame.
2 – The active time segment (animationRange).
3 – The user specified range.
4 – The user specified frame pickup string (for example “1,3,5-12”).
so…
If I wanted to get total number of frames in scene do I do this?
for i in rendTimeType.count
and then I wanted to output each frames as a separate file.
local isuffix = (0000) as integer
rendOutputFilename = “add” + isuffix +1
render()
but I am missing its path…
Uhm, no.
Once again, the total number of frames IN THE SCENE is (animationrange.end-animationrange.start+1)
What you were looking at are the settings of the Render Scene Dialog where you can have either a single frame, a range of frames with Nth step or a list of frames.
rendTimeType simply contains the integer 1,2,3 or 4 depending on which radio button time option is selected in the Render Scene Dialog. You cannot use that for looping.
The render() method allows you to pass either a framerange: (including the #active one), a fromframe: toframe: pair with nthframe: step, or you would have to create your own loop with the correct start, end and nth values and call the render() method inside the loop. See the global variables rendStart, rendEnd, rendNthFrame and rendPickupFrames which expose the actual values from the Render Scene Dialog.
But once again, the scene frame count (seen in the time slider) does not necessarily correspond to the render range set in the Render Scene Dialog. Depending on which one you meant when you said “total number of frame”, you would have to use either the animationrange interval or the values in the Render Scene Dialog.
The code you posted for adding the suffix would not work. The render() method can automatically generate the numbers for you if you are rendering a sequence. It accepts the outputfile: parameter and does NOT use the rendOutputName set in the Render Scene Dialog.
ok, I knew I was going the wrong direction there, did a bunch of searching and found some examples of rendering some output – but not frame by frame…so I am going out on a limb here and wrote this code. Going to test it now, but I already having a feeling naming convetion is messed.
totalframes = animationrange.count
local isuffix = “0000”
for i = 1 to totalframes do
(
isuffix = i as string
render frameRange:animationrange outputFile:(“add”+isuffix + 1 + “.png”) vfb:off
)
basically I need output files names as addNNNN.png, where NNNN is 0000-9999, but the 1st frame has to be named add0001.png, hence the +1. Ok testing…
[edit] uh oh. ok I used the Render Dialog and set frames to 1-20, and I get this error >>> Unknown property: “count” in (interval 0f 100f). I think this occured because I did not use proper Render Dialog code. which begs the question, if there is a chance I recieve a scene for this script, what should take presidence? Render Dialog or animationframes? Is animation frames KEY frames, I am going to set some keys now and see what happens.
[edit#2] ok I am starting to figure something out, in Time Configuration, we can set Animation values. I changed this to 10. and now my error is, Unknown property: “count” in (interval 0f 10f). So it has nothing to do with the Render Dialog. Its something in my code, something to do with float values…hrmm
ok ok hahaha. I have to learn to read people’s posts better. I updated this line
totalframes = animationrange.count
with this:
totalframes = (animationrange.end-animationrange.start+1)
since I was getting my “Unknown property: “count” in (interval 0f 10f)” error from trying to use .count on it.
“The render() method can automatically generate the numbers for you if you are rendering a sequence.”
from the Max Reference
The frame number is appended to the filename if the file image type is a single image type (.bmp, .jpg, .tga, etc.), and a frame range is being rendered
hrmm… but yet I need those this range 0001-9999, because those file names are going to be read by a separate program. I have no idea how to use render()’s inherant appendage naming convention. Doing some more research…
[edit] ok did some tweaking… Its getting closer.
for i = 1 to totalframes do
(
outputfilename = “add0000”
render frameRange:animationrange outputFile: (outputfilename + “.png”) vfb:off
)
this seems to work. but I need to fogure out how to use GetPathname somewhere in there to put the files in a directory.
AWESOME!
I finally did it!! Here’s the code I wrote in case anybody needs to know how to count animation frames and then output each frame with this type of naming convention.
totalframes = (animationrange.end-animationrange.start+1)
for i = 1 to totalframes do
(
outputfilename = "add0000"
--we want our files to be named add0000, add0001 etc...
outPath = getFilenamePath "E:\\3dsmax9\\Output\\"
--Location our files are going...
render frameRange:animationrange outputFile: (outPath + outputfilename + ".png") vfb:off
)
however, the only thing now to do, is to make sure it starts at 0001 not 0000. Ok off for more testing…
One caveat. animationRange only tells you what the time slider is set to (via the time configuration dialogue). It has nothing to do with how much animation is actually in the scene. Someone could have the animation range set to a small fraction of the overall animation because that’s what they’re working on (or the other way around).
If you want to know the range from the first frame that has movement to the last, you’re going to have to step through all the objects and look at their controllers (unless there’s a better way)