Appending a Counter to a String

Appending a Counter to a String

Anonymous
Not applicable
270 Views
2 Replies
Message 1 of 3

Appending a Counter to a String

Anonymous
Not applicable
Hi,

This might be an easy question and i hope it is. I am new to max scripting and am trying to use a counter to open a series of bitmaps within a for loop. The only thing that I cannot figure out is how to append the counter to the openbitmap function: (see below)


for count=0 to frames-1 do
{
a = openbitmap(C:\Temp\"LeftSide(**** Need Counter!! ****).png"
}

I have tried:
"LeftSide"+count+".png"
"LeftSide"+(count)+".png"
"LeftSide"count".png"

Any help would be much appreciated!!

Thanks,

Mark
0 Likes
271 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Actually i just figured it out!

a = openbitmap ("c:\Temp\Leftside"+(count as string)+".png")

Is the basic theory. I just needed the beginning parenthesis and count to be converted to a string variable.
0 Likes
Message 3 of 3

Steve_Curley
Mentor
Mentor
Depends on the filenames you have.
If your image files are "file1.png" to file9.png" and "file10.png to file99.png" etc then using "count as string" will work.
If they are "file001.png" to "file999.png" then it won't - no leading zeros. Note that a normal IFL (Image File List) uses the 2nd format, not the first.

MXS can be touchy about backslashes - either double them or use forward slashes instead.
"c:\\temp\\file1.png" or "c:/temp/file1.png".
If there is any possibility that the path or filename will have spaces, the entire string must be contained within quotes - which starts to get messy.
"\"c:\\temp\\file1.png\"" or "\"c:/temp/file1.png\""

May be easier to create the name outside of the openBitmap statement.

fName = "\"" + "C:\\temp\\Leftside" + (count as string) + ".png" + "\""
a = openBitmap fName

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes