PDA

View Full Version : MEL equivalent of MaxScripts' "FormattedPrint"?


DaveWortley
11-10-2010, 11:51 AM
Sorry bit of a MEL newbie, I want to pad my output with 0's.

$i = 1
string $newString = ("C:\test\test" + $i)

So I can output my path like these...
C:\test\test1
C:\test\test01
C:\test\test001
C:\test\test0001
i = 10 C:\test\test0010

In MaxScript I just use "FormattedPrint", what's the MEL equivalent?


Thanks


Dave

berniebernie
11-10-2010, 12:59 PM
$i = 1000;
string $newString = "C:\\test\\test" + $i;
print($newString);

NaughtyNathan
11-10-2010, 01:17 PM
@BernieBernie: LOL! (I don't think that's what he means!)

Dave, MEL has no print formatting unfortunately. Python does if that's an option to switch at this early stage?

In MEL you would have to do it manually with a "padding" proc, e.g.

global proc string padString(string $input,int $padSize,string $char)
{
int $inputSize = size($input);
for ($n=0 ; $n<($padSize-$inputSize) ; $n++)
$input = ($char+$input);
return $input;
}
// usage example:
string $numPad = `padString "10" 4 "0"`;
// Result: 0010
this becomes slower the larger the padSize (probably not that you'd ever notice) but if you wanted to use it for large space padding there are more efficient ways of doing it (substring a pad look-up string).
:nathaN

earlyworm
11-10-2010, 02:30 PM
Here's one I modified from the RMS delayedReadArchive procedure..

proc string padFrame (int $pad, int $frame)
{
string $fstr = $frame;
string $fout = "";

string $pa = "";

for ($i = size($fstr); $i < $pad; $i++)
{
$pa += "0";
}

$fout = $pa + $fstr;

return $fout;
}
/*Usage...
padFrame (4, 12);
// Result: 0012 //
*/

DaveWortley
11-10-2010, 04:01 PM
Thanks Everyone.

CGTalk Moderation
11-10-2010, 04:01 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.