View Full Version : frame padding for numbers

02 February 2011, 09:19 AM
I need to format a number in MEL once again so I can use frame padding.

I got an int value like a 1, and I want to create a string containing 001.
I thought I came across a nice command to set the format of a value once ...
but canīt remember how it was called.

I know how to do it by checking the lenght and just adding zeros of course ...
but canīt this be accomplished with just one line of code?


02 February 2011, 10:13 AM
AFAIK there's no MEL function to do this in Maya (apart from the many existing custom procs we've all written!) but you could easily do it in one line of MEL by utilising python! :D ;)
string $pad = `python ("'%04d' % "+$num)`;where $num is your MEL int variable and "4" is the padding size required.

02 February 2011, 10:26 AM
Cool, thatīs the way to go, thank you very much for pointing me to this approach :-)

02 February 2011, 04:56 PM
If you're after a one-liners you can extend Nathan's code with:
$padding = 3;
$num = 5;
string $pad = `python ("'%s0%dd' % ('%'," + $padding + ") % "+$num)`

Which is not too user friendly at all, but gives you padding control

02 February 2011, 05:27 PM
string $pad = `python ("'%0"+$padding+"d' % "+$num)`;:nathaN

CGTalk Moderation
02 February 2011, 05:27 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.