Notifications
Clear all

[Closed] Formatted Print before max 9?

Hi,

Is it possible to zero-pad an integer to a given width, I.e. “00005”, before max 9’s formattedPrint function? I am using that at the moment, but I really don’t like to cut backward compatibilty so harshly so my tool only works on the very latest version…

The manual mentions it was previously available through some “Avguard DLX Extensions” library. Is this free? And where can it be attained for max < 9?

Or is there a similar way to achieve the same outcome?

Thanks

3 Replies

Use <string>substring <string> <from_integer> <length_integer>. See the following example:

substring ((100000+5) as string) 2 5
  "00005"

The Avguard are free maxscript extensions from Larry Minton of Autodesk. They can be found at scriptspot.com.

-Eric

 rdg

the substring approach looks really fast!

I used a function for this:

fn pad inp ln ch:"0" = (
 inp = inp as string
 while inp.count < ln do inp = ch + inp
 inp
)

inp is the number you want to pad
ln is the length of the needed string
ch is an optional padding character


pad 4 4 -- outputs: "0004"
pad 4 4 ch:"x" -- outputs: "xxx4"

Georg

Ah, nice Thanks guys, really useful stuff.