[Closed] incremental filenames
So, I’ve got a script that outputs one file per frame (mesh data).
then problem I’ve got is the following:
I want the filename to be like this:
filename_0000.ext
filename_0001.ext
filename_0002.ext
etc.
But I’ve got trouble making it work like that.
All i have now is hardcoded 0’s, so when it comes to 10 it looks like this:
filename_00010.ext
instead of:
filename_0010.ext
This causes trouble for me after rendering, because 3dsmax
does not see the files as a sequence.
How can one easily add this type of counting to file output in maxscript?
thanks in advance.
You can pass your number to this function. It’ll return a string with the right amount of zeros that’ll go before your number:
fn getZeros zeroCount val =
(
zeroStr = ""
valStr = val as string
if (valStr.count < zeroCount) do
(
for x in 1 to (zeroCount - valStr.count) do zeroStr += "0"
)
zeroStr -- return value
)
Since you want it to be at least 4 numbers you can use it like this:
getZeros 4 2
>> "000"
getZeros 4 22
>> "00"
getZeros 4 222
>> "0"
getZeros 4 2222
>> ""
Why not just use formattedPrint?
result = ""
nr = 54
formattedPrint nr format:".4i" to:result
-- "0054"
formattedPrint nr format:".3i" to:result
-- "054"
etc,
-Johan
thanks to both of you, this seems to be what I need!
Thanks for the quick reply.