PDA

View Full Version : frame padding for numbers


volXen
02-11-2011, 08:19 AM
Hi,
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?

V

NaughtyNathan
02-11-2011, 09: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.
:nathaN

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

Azrail
02-11-2011, 03: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

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

CGTalk Moderation
02-11-2011, 04: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.