A handy little script that allows you to run mel commands on one or many Maya scene files (.ma or .mb). Once the specified script is run on a file, it can be saved (or not saved) in a variety of ways.
Note that this script has only been tested on Windows. Some of the mel I've used is most likely Windows only (the file dialog stuff, and some of the file handling); I'm not sure how it will actually run on OSX or linux. If you want to try it on either OS, go ahead; just make sure that the "Save" check box is unchecked, and prepare for disappointment.
Ok, with that bit of ugliness out of the way, (ahem)...
To run the script enter the following in the command line:
You can add files to the current batch in one of two ways: click the "Add Directory To Batch" button to add all of the .ma and .mb files in a given folder to the file list, or click "Add File To Batch" to add a single file. You can remove one or all files using the right click context menu.
Once you've got some files in the batch, you'll need to add some mel to the script field. Make sure that any script that you enter is properly sourced and is sure to fail gracefully.
Once that's done you're ready to specify what the script should do with a batch file once processed.
By default, files won't be saved once the script is run. This can be useful; sometimes you might just need to glean some info from a file and do something with it (eg: a mel function that writes a render batch file for a given scene). But if you do want to save the modified file, you can do that too.
To save a batch file after it has been processed, click the "Save" button. If you enable the Save button and leave the other check boxes unchecked, the modified files (or Post Script Batchfiles, PSBs for short) will be saved with the same file name (over themselves).
If you want to increment the file name, you can do so by checking the "Incremental Save" box. This will increment any numeric characters found at the end of the file name and immediately preceding the file suffix (eg: the 2 in myFile2.mb). If there are no numeric characters at the end of the file name, the script will add them, starting with 1 and a default padding of 3. If, after the file is incremented, there is found to be an existing file with the same name in the given directory, a snazzy suffix will be added: "_abBatchFile_Name_Overlap" (you can change this string in the abBFGlobals proc if you so desire).
If you want to save the modified fi..., wait, no, the PSBs, to a directory other than their source directory, you can enable the "Save To New Directory" check box. Select the new save directory using the "Select Save Directory" button.
Now you're ready to go. To run the batch immediately, click the "Run Batch" button. You'll get the option to cancel the run if the script finds any unsaved changes in the current scene.
Alternatively, you can save the batch to a .mel file, in case you want to run it from the prompt, run it again later, or just love and cherish it. Click the "Save Batch" button, and save it somewhere in your Maya scriptPath. Once saved, you can run it in the UI-less version of Maya (which is much faster than otherwise).
To do so, type:
in the Windows command line. Once Maya has loaded and you're presented with the "mel:" prompt, source your batch file (eg: "source mayaBatch.mel"), hit enter, and watch the ASCII fly.
Say you don't want to keep entering the same files into the UI every time you start a new session of Maya. Well, you can do that. Just run the following bit of mel in the Script Editor:
Save the script it spits out (below the dashed line) and paste and run it anytime you want to get back to that batch setup.
As of version 1.1, batch scripts have access to the file save boolean $gSaveBatchFile. Which means you can save batch files (or not save them) if they meet certain criteria specified by your batch script.
Note that each file in the batch will still default to the save settings specified in the UI. So, if the "Save" check box is checked, $gSaveBatchFile will be reset to true at the beginning of each batch file operation. If "Save" is unchecked and your batch script sets $gSaveBatchFile to true, the current save options ("Incremental Save", "Save To New Directory", etc) will be respected even though they're disabled in the script UI.
That's it. Enjoy.