Fun with MEL

Recently, I have been using Maya again, and found it necessary to batch process a whole bunch of animations from .ma to .fbx.  I couldn't find anything really useful online so ended up writing this MEL script.  In this case there is a reference file 'Avatar_Player' that needs to be imported also.  Feel free to use, modify and enjoy!

// Define Your File Paths

// movelist.txt is your list of motion files.  I used the old DOS command 'dir /w > movelist.txt' to generate mine

string $filePath = "C:\\Projects\\animations\\batch_test\\movelist.txt" ;
string $mainfolder =  "C:\\Projects\\animations\\batch_test" ;
string $outfolder =  "C:\\Projects\\animations\\batch_test\\dump" ;

// Open Your File  
$fileId = `fopen $filePath "r"` ;  
// Get The First Line  
string $nextLine = `fgetline $fileId` ; 
// Loop Until The String Size Is Zero (No Data)  
while (size($nextLine) > 0) {  
// Strip Whitespace From The Beginning And End Of The Line  
string $cleanLine = strip($nextLine) ;  

// Print Line  & Open File
file -f -new;
print ($cleanLine+"\n") ;  

file -o -f ($mainfolder + "\\" + $cleanLine);


// Do the work

//bind joints
select -r Avatar_Player:superMoverAll ;
setAttr "Avatar_Player:superMoverAll.bindJoints" 1;

//import reference object
file -importReference Avatar_Player.ma;

//collapse Namespace to Root
NamespaceEditor;
namespace -mergeNamespaceWithRoot -removeNamespace "WGT_Baseball_Player";

// do the bake.  Define minTime and maxTime to ensure whole animation is exported
//select -r Root ;
float $minTime = `playbackOptions -q -minTime`;
float $maxTime = `playbackOptions -q -maxTime`;

bakeResults -simulation true -t ($minTime +":" + $maxTime) -sampleBy 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true {"Root"};
//performBakeSimulationArgList 1 { "0",  "animationList"};

// Save FBX
//select -r Root ;
FBXExport -f ($outfolder + "\\" + $cleanLine);


// Get Next Line And Continue  
$nextLine = `fgetline $fileId` ;  
  
}