//Build the User Interface global proc bb_batchAutomation () { //these hold the names of the text fields global string $inputControl; global string $outputControl; global string $scriptControl; global string $bA_Window; $bA_Window = `window -title batchAutomation -width 450 -height 115 -s 0`; columnLayout -cal "left"; $inputControl = `textFieldButtonGrp -label inputDirectory -tx "put the input path here" -buttonLabel "Browse" -buttonCommand createInputBrowser`; $outputControl = `textFieldButtonGrp -label outputDirectory -tx "put the output path here" -buttonLabel "Browse" -buttonCommand createOutputBrowser`; $scriptControl = `textFieldButtonGrp -label script -tx "put the name of the script here" -buttonLabel "Browse" -buttonCommand createScriptBrowser`; setParent ..; rowLayout -nc 2 -cw2 222 222 -ct2 "both" "both" -cl2 "center" "center" ; string $runButton = `button -label Run -width 10 -command performBatchAutomation`; string $cancelButton = `button -label Cancel -width 10 -command ("deleteUI -window " + $bA_Window)`; showWindow; //make sure the window is the right size window -e -width 450 -height 115 -s 0 $bA_Window; } //This is what happens when you hit the first button //bring up the directory browser global proc createInputBrowser () { fileBrowserDialog -m 4 -fc "setInputPath" -an "pick a folder"; } //edit the textField to reflect the folder that has been picked. global proc setInputPath (string $folder,string $type) { global string $inputControl; textFieldButtonGrp -e -tx ($folder + "/") $inputControl; } //This is what happens when you hit the second button //bring up the directory browser global proc createOutputBrowser () { fileBrowserDialog -m 4 -fc "setOutputPath" -an "pick a folder"; } //edit the textField to reflect the folder that has been picked. global proc setOutputPath (string $folder,string $type) { global string $outputControl; textFieldButtonGrp -e -tx ($folder + "/") $outputControl; } //This is what happens when you hit the second button //bring up the directory browser global proc createScriptBrowser () { global string $outputControl; string $scriptLocation = `fileDialog`; setScriptPath $scriptLocation; } //edit the textField to reflect the folder that has been picked. global proc setScriptPath (string $folder) { global string $scriptControl; textFieldButtonGrp -e -tx $folder $scriptControl; } //Run the Batch Automation global proc performBatchAutomation () { global string $inputControl; global string $outputControl; global string $scriptControl; string $inputDirectory = `textFieldButtonGrp -q -tx $inputControl`; string $outputDirectory = `textFieldButtonGrp -q -tx $inputControl`; string $scriptLocation = `textFieldButtonGrp -q -tx $scriptControl`; //break the script location down to the name of the script to run. string $buffer[]; string $buffer2[]; tokenize $scriptLocation "/" $buffer; int $bufferSize = `size $buffer`; tokenize $buffer[$bufferSize - 1] "." $buffer2; string $scriptName = $buffer2[0]; //source the script. string $command = ("source \"" + $scriptLocation + "\";"); eval $command; //find all the files in the inputDirectory. string $files[] = `getFileList -folder $inputDirectory`; for ($each in $files) { //open each file in the input directory file -f -typ "mayaBinary" -o ($inputDirectory + $each); addRecentFile (($inputDirectory + $each), "mayaBinary"); //execute the script eval $scriptName; refresh; file -rename ("C:/BenBathen/BatchTests/OutputFolder/" + $each); file -save; } print "Finished the Batch Automation check the script editor for details."; }