Batching in MEL
People speak of "batching" in Maya. All this means is let the computer do the repetitive work for you. For a specific example, lets say that half way through the animation phase, your art director decides the main character of your game really needs to have a green hat to "communicate the angst of the characters plight to the player better".
For each animation already complete, you'll need to import a hat model and then constrain it to the characters head. This is the boring monotonous part of production. Help MEL help you. Maya doesn't have a built in Batch function, but it is easy enough to quickly code something up.
This example will demonstate the code I like to use for simple batching. You can utilize these concepts to automate which ever tasks it is you'll need to perform to a list of files.
Let's break that down into bit sized chucks of understanding ...
The fileDialog command launches an 'Open' window. By selecting any file in that directory, the script will now know the network path AND filename of whatever file is chosen. Store that in the
Next you need to get just the path to the file so you and MEL know what directory to work on. Luckily Maya has a built in
The one drawback to the
Now you know the directory to process. Next you'll tell Maya to look at all the files in that directory and store them in a list.
At this point its just simple for loops and other custom code to do what you like to each file. In our example, you'd import the hat, return the character to the bind pose, constrain the hat to the head, and "be kind and rewind" the animation. Lastly, you can print out a report of what happened. If you use error checking properly, you can even note what files failed for whatever reason. More on error checking later as it deserves a post all it's own.
PS- I (Chad) have moved my blog over to here.
For each animation already complete, you'll need to import a hat model and then constrain it to the characters head. This is the boring monotonous part of production. Help MEL help you. Maya doesn't have a built in Batch function, but it is easy enough to quickly code something up.
This example will demonstate the code I like to use for simple batching. You can utilize these concepts to automate which ever tasks it is you'll need to perform to a list of files.
string $fullPathAndName = `fileDialog`;
string $sourcePath = dirname($fullPathAndName);
string $sourcePath = ($sourcePath + "/");
string $myFiles[] = `getFileList -fld $sourcePath -filespec "*.mb"`;
for ($eachFile in $myFiles)
{
//your tasks go here
}
print ("Done doing stuff for all the files in this directory " + "\"" + $sourcePath + "\"" + "!" + "\n");
Let's break that down into bit sized chucks of understanding ...
string $fullPathAndName = `fileDialog`;
The fileDialog command launches an 'Open' window. By selecting any file in that directory, the script will now know the network path AND filename of whatever file is chosen. Store that in the
$fullPathAndName variable.Next you need to get just the path to the file so you and MEL know what directory to work on. Luckily Maya has a built in
dirname command. You provide the command a full path and filename string and it will automatically return just the directory path. Store that in the $sourcePath variable.The one drawback to the
dirname command is it doesn't include the trailing "/" at the end so you'll have to reassign the $sourcePath variable to include its current contents plus the trailing "/". This line string $sourcePath = ($sourcePath + "/"); does exactly that.Now you know the directory to process. Next you'll tell Maya to look at all the files in that directory and store them in a list.
string $myFiles[] = `getFileList -fld $sourcePath -filespec "*.mb"`; is the key here. The command getFileList does what it says, you're telling MEL where to get the files from by the -fld $sourcePath bit. I am sure you can guess that the -fld is short for folder. Use a string array called $myFiles[] or something similar to store the files.At this point its just simple for loops and other custom code to do what you like to each file. In our example, you'd import the hat, return the character to the bind pose, constrain the hat to the head, and "be kind and rewind" the animation. Lastly, you can print out a report of what happened. If you use error checking properly, you can even note what files failed for whatever reason. More on error checking later as it deserves a post all it's own.
PS- I (Chad) have moved my blog over to here.

3 Comments:
Hi Chad,
Its funny I just wrote a batching script to save my teams work load. I managed to slap it together very quickly (too busy helping others) but still needed to update a good error log and a progression bar.Seeing you going to do a piece on errors, and maybe a progression bar :0). Great stuff your doing with this blog, its nice to see sharing info, and congratulations with the newly born, lack of sleep and changing nappies :0). I became a farther for the 2nd time 5 months ago and sleep has come back into the horizon, still changing nappies tho :0).
-steve
By
steve gould, at Tuesday, August 08, 2006 5:26:00 AM
Steve,
Thanks for the kind words. Congrats on your 5 month old. And Congrats to you that sleep has returned! Ahh sleep, I miss you. Anyway, it's really hectic at home and the office, so I am not sure how long it will be before I get a post on error checking rolling. I'll see what I can do.
Have fun with your blog too.
Chad
By
Chad, at Tuesday, August 08, 2006 8:24:00 AM
Chad,
I fully understand, look forward to your updates.
-steve
By
steve gould, at Wednesday, August 09, 2006 1:54:00 AM
Post a Comment
Links to this post:
Create a Link
<< Home