View Full Version : Appending an array of numbers to a string

10 October 2005, 03:27 PM

a little question from a beginner. :D

I want to clear the whole materialeditor and replace the slots with Vray-materials.
The names of the new materials should look like this:

Vray_01, Vray_02 .. Vray_24

fn cleanvray = (
for i = 1 to 24 do (
setMEditMaterial i (VRayMtl())
meditMaterials[i].name = "VrayMat_" + ???

How do I append numbers (1..24) to a string (VrayMat_)?


10 October 2005, 03:39 PM
First conver the number to a string:

"the number seven = " + (7 as string)
"blah" + (myarray[3] as string)

Don't forget to put parenthesis around the whole thing that you want to be considered 1 string

10 October 2005, 03:40 PM
Hi Uli,

Welcome to maxscript!

x="number "
"number "
x+=123 as string
"number 123"

FYI you can save your maxstart.max file in the scenes directory with VRay materials in the materials editor and it should remember! you can also set your renderer to be VRay.

I use a similar script all the time to clear the editor and also place the environment in the last slot.

10 October 2005, 04:09 PM
hey guys, where is the zero of Vray_01 ?

fn getFormatedString n nMax =
nString=n as string
if dif>0 do (
addString="" ; for a=1 to dif do append addString "0"

numberSize=(maxNumber as string).count
for i=1 to maxNumber do
myString="Vray_"+getFormatedString i numberSize
format "%\n" myString

10 October 2005, 04:22 PM
[QUOTE=prettyPixel]hey guys, where is the zero of Vray_01 ?[QUOTE]

:D ???????

10 October 2005, 04:42 PM
That's nothing. Apparently nobody is interested by the zero.

10 October 2005, 05:02 PM
I didn't think he'd have a problem with the zero!

Tell me prettyPixel, do you have all the setw / setprecision functions written out? :)

10 October 2005, 05:14 PM
hey guys, where is the zero of Vray_01 ?

Fun with functional programming:

fn addZeros theValue theDigits = ( substring "0000000000" 1 (theDigits-((theString = theValue as string).count)) + theString )

theFormattedString = addZeros 1 2
theFormattedString = addZeros 123 5

Caveat: passing a longer value than the number of digits will return all zeros. It would require an additional if test to catch that, but for general cases like file names (4 digits) and the material editor samples (2 digits) it is pretty short...

10 October 2005, 05:16 PM
The zero is nothing, but the zero makes the difference.
It's the same with the size :)

EDIT: nice function bobo

CGTalk Moderation
10 October 2005, 05:16 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.