I went about tidying it up and came up with this little number in mel.
global proc string rt_addPadding(int $num,int $padding)
{
int $lengthNum=size(string($num)) ;
string $padString;
if($lengthNum<$padding)
for($i=0;$i<($padding-$lengthNum);$i++)
$padString=$padString+"0" ;
return $padString+string($num) ;
}
Which works ok, and then a couple of minutes searching I came across a post by Nathan which instead uses python (and is far better).
string $pad = `python ("'%0"+$padding+"d' % "+$num)`;
This then is used as this.
global proc string rt_addPadding(int $num,int $padding)
{
return `python("'%0"+$padding+"d' % "+$num)` ;
}
Useful :)
Aha! Exactly what I need for my naming convention :) Thanks for both the MEL and Python solution, Lee.
ReplyDeleteNo probs Jimmy!
ReplyDelete