////////////////////////////////////////////////////////////// ///// This should take all the steps to make the rig //// ///// and create a rigging mel script for it //// ///// Author: Marc Thyng //// ///// version: 1.0 //// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ///// This creates a file and records the script editor //// ///// output into the file specified. //// ///// Be careful not to overwrite a file. //// ///// The script will prompt you to overwrite or append //// ////////////////////////////////////////////////////////////// global proc mtMelRecorder() { if (`window -q -ex recordWin`) deleteUI recordWin; string $recorderWin = `window -title "winRecorder" -iconName "recorder" -widthHeight 240 100 -maximizeButton off -sizeable off recordWin`; global string $mtRecordButton; rowColumnLayout -nc 3 -w 220 -cw 1 40 -cw 2 110 -cw 3 50 -cs 3 3 createRecordRCL; text -label " Script" -w 45; $mtScriptName = `textField -en true -tx "exampleRig"`; $mtRecordButton = `button -label "Record" -bgc .7 .1 .1 -c ("recorder(" + "`textField -q -tx " + $mtScriptName + "`);") -w 80 -align "center"`; showWindow $recorderWin; window -e -widthHeight 220 60 $recorderWin; } global proc recorder(string $userFileName) { $userFileName = ($userFileName + ".mel"); string $mtScriptDir = `internalVar -userScriptDir`; $scriptFileName = (`internalVar -userScriptDir` + $userFileName); int $match = 0; global string $mtRecordButton; string $buttonLabel = `button -q -l $mtRecordButton`; if ($buttonLabel == "Record") hitRecord($scriptFileName, $userFileName); else if ($buttonLabel == "Pause") hitPause(); else error "shouldn't get here"; } global proc hitRecord(string $scriptFileName, string $userFileName) { string $mtScriptDir = `internalVar -userScriptDir`; // check files in script folder string $mtFiles[] = `getFileList -folder $mtScriptDir -filespec "*.mel"`; int $flag = 0; for ($each in $mtFiles) if ($each == $userFileName) $flag = 1; if ($flag == 1) winFileExists($scriptFileName, $userFileName); else if($flag == 0) winRecorder($scriptFileName, $userFileName); } global proc hitPause() { global string $mtRecordButton; string $buttonLabel = `button -q -l $mtRecordButton`; print "}"; button -e -l "Record" $mtRecordButton; scriptEditorInfo -hfn ""; scriptEditorInfo -wh false; } global proc winRecorder(string $scriptFileName, string $fileNameOnly) { global string $mtRecordButton; string $buttonLabel = `button -q -l $mtRecordButton`; string $fileNameOnly = match ("[^.]*", $fileNameOnly); if ($buttonLabel == "Record") { $fileId =`fopen $scriptFileName`; fprint $fileId ("global proc " + $fileNameOnly + "() {\n"); fclose $fileId; button -e -l "Pause" $mtRecordButton; scriptEditorInfo -hfn $scriptFileName; scriptEditorInfo -wh true; } else error "shouldn't get here"; } global proc winFileExists(string $scriptFileName, string $userFile) { string $fileExistsWin = `window -title ($userFile + " Exists") -iconName "File Exists" -widthHeight 160 55 -sizeable off`; rowColumnLayout -numberOfColumns 2 -columnWidth 1 80 -columnWidth 2 80 -cs 1 50; button -label "Overwrite" -c ("mtOverwrite(\"" + $userFile + "\"); deleteUI -window " + $fileExistsWin); button -label "Append" -c ("mtAppend(\"" + $userFile + "\"); deleteUI -window " + $fileExistsWin ); setParent ..; showWindow $fileExistsWin; window -e -widthHeight 275 55 $fileExistsWin; } global proc mtOverwrite(string $userFile) { string $scriptFileName = `internalVar -userScriptDir`; $scriptFileName = ($scriptFileName + $userFile); $fileId = `fopen $scriptFileName "w"`; fclose $fileId; winRecorder($scriptFileName, $userFile); } global proc mtAppend(string $userFile) { global string $mtRecordButton; string $buttonLabel = `button -q -l $mtRecordButton`; string $scriptFileName = `internalVar -userScriptDir`; $scriptFileName = ($scriptFileName + $userFile); /// collect the data so far $fileId = `fopen $scriptFileName "r"`; string $fileToAddTo; string $fileToAddTo = `fread $fileId $fileToAddTo`; int $sizeOfFile = size($fileToAddTo); //// remove the } string $newFile; if ($sizeOfFile>0) { $sizeOfFile--; $newFile = `substring $fileToAddTo 1 $sizeOfFile`; } else error "file is empty, overwrite"; fclose $fileId; $fileId = `fopen $scriptFileName "w"`; fprint $fileId $newFile; fclose $fileId; button -e -l "Pause" $mtRecordButton; scriptEditorInfo -wh true; scriptEditorInfo -hfn $scriptFileName; }