Notifications
Clear all

[Closed] Appending an array of numbers to a string

Hello,

          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_)?
       
       Thx,
       Uli
8 Replies

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

Hi Uli,

Welcome to maxscript!


x="number "
"number "
x+=123 as string
"number 123"
[size=2]

[/size]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.

hey guys, where is the zero of Vray_01 ?

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

maxNumber=25
numberSize=(maxNumber as string).count
for i=1 to maxNumber do
	(
	myString="Vray_"+getFormatedString i numberSize
	format "%
" myString
	)
1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

Fun with functional programming:

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

 theFormattedString = addZeros 1 2
 "01"
 theFormattedString = addZeros 123 5
 "00123"
 
 

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…

[QUOTE=prettyPixel]hey guys, where is the zero of Vray_01 ?

???

That’s nothing. Apparently nobody is interested by the zero.

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?

The zero is nothing, but the zero makes the difference.
It’s the same with the size

EDIT: nice function bobo