proc createRecursiveFileList (string $currentPath) { int $includeDae = `checkBox -q -v affectedDaeBox`; int $includeAnm = `checkBox -q -v affectedAnmBox`; int $includeAll = `checkBox -q -v affectedAllBox`; $currentPath = ($currentPath + "/"); string $currentFiles[] = `getFileList -folder $currentPath`; for ( $i = 0; $i < size( $currentFiles ); $i++ ) { //ignore files or directories starting with "." if (`match "^." $currentFiles[$i]` != ".") { //search for directories if (`filetest -d ($currentPath + $currentFiles[$i])`) { // recall function (go recursive into subdirs) createRecursiveFileList ($currentPath + $currentFiles[$i]); } else { //is a file...see what to do: string $filename = ($currentPath + $currentFiles[$i]); string $baseFilename = basename( $filename, ".mb" ); string $baseFilenameWExt = basename( $filename, "" ); string $fullPathFilenameSansExt = `substitute $baseFilenameWExt $filename $baseFilename`; string $fullPathFilenameDae = ($fullPathFilenameSansExt + ".dae"); string $fullPathFilenameAnm = ($fullPathFilenameSansExt + ".anm"); int $includeCurrent = 0; if (fileExtension ($baseFilenameWExt) == "mb") { //test to see if file should be used if ($includeAll) { $includeCurrent = 1; } else if (($includeDae) && (`file -q -exists $fullPathFilenameDae`)) { $includeCurrent = 1; } else if (($includeAnm) && (`file -q -exists $fullPathFilenameAnm`)) { $includeCurrent = 1; } } if ($includeCurrent) { global int $numFilesToProcess; global string $filesToProcess[]; $filesToProcess[$numFilesToProcess] = ($currentPath + $currentFiles[$i]); $numFilesToProcess++; } } } } } global proc batchButtonAction () { string $baseDir = `textFieldButtonGrp -q -text baseDirTextGroup`; string $animBaseFile = `textFieldButtonGrp -q -text animBaseFileGroup`; string $animRootNode = `textFieldButtonGrp -q -text animRootNodeGroup`; string $animNamespace = `textFieldGrp -q -text animNamespaceGroup`; int $doCgfxToColladafx = `checkBox -q -v cgfxToColladafxBox`; int $doCloseWindows = `checkBox -q -v closeWindowsBox`; int $doExportModified = `checkBox -q -v exportModifiedBox`; int $doExportAll = `checkBox -q -v exportAllBox`; string$customScript = `textFieldGrp -q -text customScriptGroup`; string$customCommand = `textFieldGrp -q -text customCommandGroup`; createRecursiveFileList $baseDir; global string $filesToProcess[]; //TODO: prompt number or list of files to process if > X or if basedir == default //("You are about to process " + $TEMPnum + " files in the following directory:\n" + $baseDir + "\nIs that OK?"); deleteUI batchToolWindow; //TODO: Log window with errors/progress for ($i = 0; $i < size($filesToProcess); $i++) { int $modifiedFile = 0; global string $filesToProcess[]; //open file pv_performAction $filesToProcess[$i] "Best Guess"; file -f -options "v=0" -typ "mayaBinary" -o $filesToProcess[$i]; //run through list of things that need to be done if ($customScript != "") { eval "source $customScript"; $modifiedFile = 1; } if ($customCommand != "") { eval $customCommand; $modifiedFile = 1; } if ($doCgfxToColladafx) { string $CgfxToColladafxResult = `cgfxToColladafx`; if ($CgfxToColladafxResult == "modifiedFile") {$modifiedFile = 1;} else if ($CgfxToColladafxResult == "cgfxPluginLoaded") { global string $filesWithCgfx[]; global int $numFilesWithCgfx; $filesWithCgfx[$numFilesWithCgfx] = $filesToProcess[$i]; $numFilesWithCgfx++; } } if ($doCloseWindows) { //TODO: Create close windows proc/.mel //$didCloseAllWindows = `closeAllWindows`; //if ($didCloseAllWindows) {$modifiedFile = 1;} } if (($doExportAll) || (($doExportModified) && ($modifiedFile))) { source colladaExport.mel; $didColladaExport = `doColladaExport`; if ($didColladaExport) { global string $filesExported[]; global int $numFilesExported; $filesExported[$numFilesExported] = $filesToProcess[$i]; $numFilesExported++; } } //save if modified if ($modifiedFile) { file -save; global string $filesModified[]; global int $numModified; $filesModified[$numModified] = $filesToProcess[$i]; $numModified++; } } //Summary global string $filesToProcess[]; global int $numFilesToProcess; global string $filesModified[]; global int $numModified; global string $filesExported[]; global int $numFilesExported; global string $filesWithCgfx[]; global int $numFilesWithCgfx; print "\n\nModified the following files:\n"; print $filesModified; print "\nExported the following files:\n"; print $filesExported; string $message = ("Modified " + $numModified + " .mb files\nExported " + $numFilesExported + " .dae files"); if ($numFilesWithCgfx > 0) { print "\nFiles using the CgFx plugin:\n"; print $filesWithCgfx; $message = ($message + "\n" + $numFilesWithCgfx + " files are still using the CgFx plugin"); } print ("\n" + $message + "\n"); print "Export complete\n"; confirmDialog -title "Export complete" -message $message -button "OK" -defaultButton "OK"; } global proc setBatchBaseDir (string $baseDir, string $fileType) { textFieldButtonGrp -edit -text $baseDir baseDirTextGroup; } global proc setBatchAnimBaseFile (string $animBaseFile, string $fileType) { textFieldButtonGrp -edit -text $animBaseFile animBaseFileGroup; } global proc getSelectedBaseNode (string $animBaseFile, string $fileType) { //TODO: actually create this proc textFieldButtonGrp -edit -text $animRootNode animRootNodeGroup; } global proc batchTool () { //reset global variables global string $filesToProcess[]; global int $numFilesToProcess; global string $filesModified[]; global int $numModified; global string $filesExported[]; global int $numFilesExported; global string $filesWithCgfx[]; global int $numFilesWithCgfx; clear ($filesToProcess); $numFilesToProcess = 0; clear ($filesModified); $numModified = 0; clear ($filesExported); $numFilesExported = 0; clear ($filesWithCgfx); $numFilesWithCgfx = 0; //set defaults string $baseDir = `workspace -fn`; int $includeDae = 1; int $includeAnm = 0; int $includeAll = 0; string $animBaseFile; string $animRootNode; string $animNamespace; int $doCgfxToColladafx = 0; int $doCloseWindows = 0; int $doExportModified = 1; int $doExportAll = 0; string $customScript; string $customCommand; window -title "Batch Tool" -menuBar true -resizeToFitChildren true batchToolWindow; columnLayout -columnWidth 500 -adjustableColumn 1; textFieldButtonGrp -label "Base Directory" -cw 1 80 -cw 2 390 -cw 3 30 -text $baseDir -buttonLabel "..." -buttonCommand "fileBrowserDialog -m 4 -fc setBatchBaseDir -an \"Choose a starting directory:\"" baseDirTextGroup; setParent ..; frameLayout -collapsable false -label "Files to Process" -width 500; columnLayout -columnWidth 500; checkBox -label "Files with .dae" -value $includeDae affectedDaeBox; checkBox -label "Files with .anm" -value $includeAnm affectedAnmBox; checkBox -label "All .mb Files" -value $includeAll affectedAllBox; setParent ..; setParent ..; frameLayout -collapsable true -collapse 1 -label "Transfer Animation (not functional)" -width 500; columnLayout -columnWidth 500; textFieldButtonGrp -label "Base File" -cw 1 80 -cw 2 390 -cw 3 30 -text $animBaseFile -buttonLabel "..." -buttonCommand "fileBrowserDialog -m 0 -fc setBatchAnimBaseFile -an \"Choose a base file:\" -ft mayaBinary" animBaseFileGroup; textFieldButtonGrp -label "Root Node" -cw 1 80 -cw 2 150 -cw 3 100 -text $animRootNode -buttonLabel "Use Selected" -buttonCommand getSelectedBaseNode animRootNodeGroup; textFieldGrp -label "Namespace" -cw 1 80 -cw 2 150 -text $animNamespace animNamespaceGroup; setParent ..; setParent ..; frameLayout -collapsable true -collapse true -label "Custom .mel Script or Command" -width 500; columnLayout -columnWidth 500; textFieldGrp -label "Script" -cw 1 60 -cw 2 150 -text $customScript customScriptGroup; textFieldGrp -label "Command" -cw 1 60 -cw 2 150 -text $customCommand customCommandGroup; setParent ..; setParent ..; frameLayout -collapsable false -label "Commands" -width 500; columnLayout -columnWidth 500; checkBox -label "Convert Materials (cgfx to colladafx)" -value $doCgfxToColladafx cgfxToColladafxBox; checkBox -label "Close All UI Windows (not functional)" -value $doCloseWindows closeWindowsBox; checkBox -label "Export .dae (Modified Files)" -value $doExportModified exportModifiedBox; checkBox -label "Export .dae (All Files)" -value $doExportAll exportAllBox; setParent ..; setParent ..; rowColumnLayout -nc 2 -columnWidth 1 250 -columnWidth 2 250; button -label "Go!" -width 250 -command "batchButtonAction"; button -label "Close" -width 250 -command "deleteUI -window batchToolWindow"; showWindow batchToolWindow; }