PDA

View Full Version : Batch importing obj files


pika
05-22-2004, 02:26 AM
Hello.

I want to import many obj files to to maya, and thinking about
making a batch MEL script to import all the obj files in a specific
folder.

I was able to import a file if I specify the exact name of the file,
but where I got stuck is to make a loop to import other objs in the same directory.

This is a script I extracted from the script editor, and I am wondring how I can modify to make a loop to import other objs.

file -import -type "OBJ" -rpr "test" -options "mo=1" "C:/objs/test.obj";

Simply changing

"C:/objs/test.obj"; to

"C:/objs/*.obj";

did not work, and here is what want to do;

find a file in a specific folder in order of name
import the file
ignore the already imported file,
then find the second file in the same directory,
import the file,
find the third file
and so on... until the last file.

I am thinking the key would be the file input script to
make the loop like above, although I am not sure where
I could start.

I appreciate if any body could help me.

Thank you very much,

leisure
05-22-2004, 03:33 AM
I recently had to do something similar, except I was exporting the files in a directory.

You want to use the getFileList. Do something like this.


string $sourceFiles[] = `getFileList -folder ($sourceName + "\\") -filespec "*.obj"`;

that'll load your file names into an array, then you can import them one at a time using a loop.

pika
05-22-2004, 02:00 PM
This is excellent!

I am going to create a loop using this.

Thanks a million!

estaxver
08-18-2005, 10:56 PM
For the scripting-challenged blokes like me, what is the final coding of the loop for
file -import -type "OBJ" -rpr "test" -options "mo=1"
+
string $sourceFiles[] = `getFileList -folder ($sourceName + "\\") -filespec "*.obj"`;?
Thank you!

leisure
08-29-2005, 09:28 PM
Sorry it took me a little while to respond. I was on vacation.

I'm not the best at scripting, but this is how I loop it. Hope it helps.

int $x = 0;
while ((size($sourceFiles[$x])) > 0){
//open a file
print ($sourceFiles[$x] + "\n");
file -new -f;
file -type "mayaBinary" -o ($sourceName + "/" + $sourceFiles[$x]);

//put your mel commands here
string $batchText = ;mel commands
eval $batchText;

//save
file -f -type "mayaBinary" -s;
$x++;
}

estaxver
08-30-2005, 04:02 PM
Hey leisure,
I did this: string $sourceFiles[] = `getFileList -folder "X:/maya/objs/" -filespec "*.obj"`;

int $x = 0;

while ((size($sourceFiles[$x])) > 0){

file -import -type "OBJ" -options "mo=1" -pr $sourceFiles[$x];

$x++;

};

and it worked! Thanks!

Testing your patience further, and regarding the bit of your script that reads:

//put your mel commands here
string $batchText = ;mel commands
eval $batchText;
could you please post an example of "mel commands", whatever, just to see how are you using that part of the script.

Esta

leisure
08-30-2005, 05:11 PM
The way I use this script is as a batch processor, so the "mel commands" part is just whatever mel commands I want to run on the file. It's actually hooked up to a gui text box. What I posted has a lot of the original script cut out of it, so parts might not make that much sence, like making a new file, opening a file then closing it. You wouldn't do all that if you're just importing. I should of simplified it, but I'm lazy, I mean efficient. :)

It's a pretty short script so I can post it if you want.

estaxver
08-30-2005, 06:35 PM
oh yes, please do post or pm it, at least the commands after
string $batchText =
It's just to see the syntaxis in a real script, even if it comes from a trimmed one.
Cheers,
Esta

CGTalk Moderation
08-30-2005, 06:35 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.