[Closed] Using file name as a variable
Hi everybody,
I´ve got a short question. Basically what I want to do is to process several dozen geometry files and render those to a certain path. While this seems like an easy task, please keep in mind that I am a humble newbie when it comes to MaxScript. I know it is all in the Script reference, however I am still trying to find my way around, so any help is much appreciated.
I´d like to use the file name (consisting of a bunch of numbers) as a render and file output path. For this I believe (correct me if I am wrong) I have to take the file name, output it as a string (similar to the “getmaxfileobjectnames” command) and pass it on to a variable which I then can use to set the file and render output paths.
My problem is finding the method of storing the file name as a string. At least I haven´t found it in the script reference. This very frustrating as I have used Max for several years and right now I feel like a total jerk being blocked in my work by such a basic work step
Cheers
Chris
Hi there, is this it?
tPath=maxFilePath
tFilename=getFilenameFile maxFilename
tOutput=tPath+tFilename+".tga"
Returns:
"C:\Documents and Settings\Administrator\My Documents\3dsmax\scenes\"
"ttt"
"C:\Documents and Settings\Administrator\My Documents\3dsmax\scenes tt.tga"
Hi Arthur,
yeah, that looks good. Just what I need to continue my scripting.
Thanks for your help, man
Chris
Hi everybody,
back again with a first code snippet. Again, as I am a humble beginner that´s smashing his head against the wall (At least thats how I feel ;)) I´d be interested in some feedback, as I believe this whole thing could be a lot simpler but anyway, here´s what it is supposed to do:
I´d like to take a filename that is structured in 7 numbers and use it to create a path I´m going to use as a render output. Numbers 1 and 2 define the first folder, 3 and 4 the second folder and 5, 6 and 7 the last folder. For example a filename called 0102003 should be rendered to c:\myproject\renderoutput\01\02\003.
So far so good. This is what I came up with:
–this searches for the filename, thanks to Kameleon
tFileName=getFilenameFile maxFilename–For ease of testing filename = tFileName can be replaced with filename = 0102003
filename = tFilename
bspace = “_”
first = substring tFilename 1 2
bspace_fix = substring bspace 1 1
first_bspace = append first bspace_fix
second = substring tFilename 3 2
second_bspace = append second bspace_fix
third = substring tFilename 5 3
third_bspace = append third bspace_fix
path1 = append first_bspace second_bspace
path2 = append path1 third_bspace
path3 = append bspace_fix path2
path4 = append “C:\myproject\renderoutput” path3
As you can see, I´ve been struggling with the backspace bit as a simple “” is not properly recognized by MaxScript (beats me why, need to learn more, I guess), so thats why I came up with bspace_fix thing.
So, I guess this is far too complicated ;). The big question is, how do I make it easier?
Thanks in advance
Chris
Hi again, just use @”” it does the job, it’s a life saviour, I’ve been using it alot when dealing with filenames and directories
Edit:
I actually stopped and looked at what you where trying to achieve. If your filenames always follow that rule, then I guess there’s an easier way, look at this:
tfile="c:\0102003.max"
filename=getfilenamefile tfile
tpath=@"c:\myproject\renderoutput\"+filename[1]+filename[2]+@"\"+filename[3]+filename[4]+@"\"+filename[5]+filename[6]+filename[7]
Cyas!
Hey Artur,
you really saved my day again. I knew this whole append/substring etc… couldn´t have been it, but that´s all I managed. Your code is a lot more clearer.
Anyway I learned a lot about strings today (the hard way ;)), so I guess that wasn´t for nothing.
Have a nice evening and thanks for your help
Chris