PDA

View Full Version : MAXscript: batch file query


bentllama
10-18-2002, 07:58 PM
Below you will find a MAX script I am working on…

Seeing as you all have helped me greatly in the past, I have another MAXscript question for you.

Can I tokenize a list of directories so the script processes the entire list? I want to list directories that contain specific file...and export those files with the source file name into that same directory. How can i batch it to do this?

Thanks in advance for your help.


-- MAX2FBX-test.ms
-- Exports MAX files in a source directory to FBX files in a destination directory
-- with the same filename as the source MAX files.

Dir = #("C:\\temp\\max2fbxSource\\")
MaxFiles = #()

For d in Dir do Join MaxFiles (getFiles (d + "*.max"))
for f in MaxFiles do
(
LoadMAXFile f ;
ExportFile ("C:\\temp\\max2fbxExported\\" + getFilenameFile (MaxFileName) + ".fbx") ;
)

LFShade
10-18-2002, 10:22 PM
Let me see if I've got this straight. Given a list of directories, you'd like to go through each directory and find all .max files, then export them as .fbx into the same directory they came from. Right?

Should be easy, as long as you already know what directories you're looking in. If so, it might look something like this:

Dirs = #("C:\Dir1", C:\Dir2", "C:\Dir3")

for dir in Dirs do
(
for f in ( getFiles (dir + "*.max") ) do
(
loadMaxFile f
exportFile ( dir + maxFileName + ".fbx" )
)
)


If I'm missing the point, let me know:)

bentllama
10-18-2002, 11:53 PM
Dirs = #("C:\Dir1", C:\Dir2", "C:\Dir3")


So the directories only need a comma sseperator? thats it? thats what was confounding me all this time! Arrrggghh! :)

Thanks for the help. I am gonna go see if I can finish the script now...

bentllama
10-19-2002, 12:29 AM
That did the trick. I was expecting something longer [like I would do in MEL]...

LFshade, I am so happy I could touch you...:love:

LFShade
10-19-2002, 12:48 AM
Ha! (no touching please:shame: ). But I'm glad it worked out for you.

Here's another thing you might find useful: you can build a recursive function to retrieve an entire directory tree, given a toplevel directory.

fn getDirTree dir &array =
(
if not matchPattern dir pattern:"*\\" do dir += "\\"
subdirs = getDirectories ( dir + "*" )
for sub in subdirs do
(
append array sub
getDirTree sub array
)
)

When you call this function, you pass in a path string and an empty array. When it finishes, the array will contain all directories under the one you passed in. In other words,

foo = #()
getDirTree "C:\\3dsmax4\\" foo

would put every single subdirectory of C:\3dsmax4\ into foo. That way if all the files you want to get at live in folders under a single directory, you can easily build your directory list to use with the code I provided earlier.

The function even has a little tolerance for the format of the directory string you pass in. You could use either "C:\\dir\\" or "C:\\dir", and it would still work (provided the directory is valid).

:beer:

CGTalk Moderation
01-13-2006, 03:00 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.