Wednesday, August 16, 2006
Tuesday, June 06, 2006
Batching in MEL
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
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
dirnamecommand. You provide the command a full path and filename string and it will automatically return just the directory path. Store that in the
The one drawback to the
dirnamecommand is it doesn't include the trailing "/" at the end so you'll have to reassign the
$sourcePathvariable 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
getFileListdoes what it says, you're telling MEL where to get the files from by the
-fld $sourcePathbit. I am sure you can guess that the -fld is short for folder. Use a string array called
$myFilesor 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.
Wednesday, September 14, 2005
Wednesday, September 07, 2005
Master Class Notes
Thursday, September 01, 2005
Workflow improvements: Connection Editor
I decided that I would like it to load the first selection to the left side of the connection editor, as I always have it set to from -> to. Then anything else selected would open on the right side.
// SCRIPT: ijConnectionEditor
// AUTHOR: Ian Jones - firstname.lastname@example.org
// DATE: September 1, 2005
// Version: 1.0
// DESCRIPTION: Opens the connection editor and loads left/right side based on
// a selection
// ASSUMPTIONS: Connection Editor is set to: from -> to
global proc ijConnectionEditor()
// Save the current selection/size
string $selection = `ls -sl`;
int $numSelections = `size($selection)`;
// If selection exists: load to the left side of the CE
if ( $numSelections > 0 )nodeOutliner -e -replace ( $selection ) connectWindow|tl|cwForm|connectWindowPane|leftSideCW;
// If selection exists: load to the right side of the CE
if ( $numSelections > 1 ) nodeOutliner -e -replace ( $selection ) connectWindow|tl|cwForm|connectWindowPane|rightSideCW;
// If more than 2 objects selected
// add additional to the right side.
if ( $numSelections > 1 )
for( $n=2; $n<($numSelections ); $n++ )
nodeOutliner -e -addObject $selection[( $n )] connectWindow|tl|cwForm|connectWindowPane|rightSideCW;
Already saving me a bunch of time. Hope you enjoy.
Monday, August 29, 2005
Batches? We DO need stinking batches
I am tinkering with my next post, which I hope to have up by this weekend. I want to talk a bit about creating a batch script.
Do you have a lot of files that you need to alter in the same way? Do you wish that there was a way to automatically process all these files at once? Well batching is for you!
Monday, August 22, 2005
Here's something i have in my custom modeling marking menu that toggles on the quickdragselect option in the preferences. I don't *think* there's another way to turn it on and off quickly without going into the prefs, so this proves to be super handy when i'm manipulating verts. It's even better when you envoke the soft mod tool.
if (`selectPref -q -cld`)
selectPref -cld 0;
selectPref -cld 1;
For those that don't know what clickdragselect is, it basically lets you click and drag (with move, rotate, or scale), as opposed to clicking, letting go, then middle mouse dragging the selection.
Hmm.. can that code be even more simplified?