//////////////////////////////////////////////////////////////////////////////////////// // // procedure Name: int pubIncrementSave() // // Date: Jan 2005 // // Desciption: //////////////////////////////////////////////////////// // procedure to get valid named mayaAscii files in a directory //////////////////////////////////////////////////////// global proc string[] boldGetValidFileListInDir(string $absDirectory) { if (!endsWith($absDirectory, "/")) { $absDirectory = ($absDirectory + "/"); } string $currentDirContent[], $validFileNames[]; string $element; int $i =0; $currentDirContent = `getFileList -folder $absDirectory -filespec "*.ma"`; for ($element in $currentDirContent) { //if (isValidString($element, "([a-zA-Z0-9]+)([a-zA-Z0-9_])*")) { $validFileNames[$i++] = $element; //} } $currentDirContent = `getFileList -folder $absDirectory -filespec "*.mb"`; for ($element in $currentDirContent) { //if (isValidString($element, "([a-zA-Z0-9]+)([a-zA-Z0-9_])*")) { $validFileNames[$i++] = $element; //} } $currentDirContent = `getFileList -folder $absDirectory`; for ($element in $currentDirContent) { if ((`match "_[vV][0-9]+$" $element` != "") || (`match "_[0-9]+$" $element` != "" ) || (`match "_[a-zA-z]+$" $element` != "" )) { $validFileNames[$i++] = $element; } } //print $validFileNames; return $validFileNames; } ///////////////////////////////////////////////////////////////////////////////// // checkVersion & increment procedure to find highest version in dir // variable passed is the middle Name section, devoid of version or locationPrefix // such as antiOxidantsClothingStartSim // return is the version without _ in front, so v01_01 for example // global proc string boldGetNextFileVersion(string $fileName, string $sceneDir) { //string $fileName = "gbl_ass_chr_antiOxVeeFacialSaveTest"; //string $fileName = "antiOxidants"; string $existingFileNames[]; ////////////////////////////////////////////////////////////////////////////////////// // test is fileName is passed with version attached, then castrate // // ensure we get only the baseName and not a full file path that may have been passed // $fileName = `match "[^/\\]*$" $fileName`; // get unversioned fileName // if (`gmatch $fileName "*_[vV][0-9]*"`){ $fileName = `substitute "\.[a-zA-Z]*$" $fileName ""`; // delete file ending if present $fileName = `substitute "_[0-9]+$" $fileName ""`; // delete minor version if present $fileName = `substitute "_[vV][0-9]+$" $fileName ""`; // delete major Version if present } // only find newFileVersion if the name is not new // if (($fileName != "newName") && ($fileName != "")) { string $workLocation = $sceneDir; string $filesInWork[], $maxFileVersionWork, $maxMinVersionWork, $maxMajVersionWork, $file, $dir, $version, $minV, $majV, $returnString; int $i, $vw, $vW; //$vw - minorWorkVersion, $vW - MajorWorkVersion $vw = $vW = 0; $tmp = `boldGetValidFileListInDir($workLocation)`; // minor version and major version clear $filesInWork; for ($foo in $tmp){ if (`gmatch $foo ("*" + $fileName + "_[vV][0-9]*")`){ $filesInWork[size($filesInWork)] = $foo; } } //print $filesInWork; if (`size $filesInWork` > 0){ // //get highest version // starting with Work files for ($file in $filesInWork) { // check and separate minor and major versions // work always has major and minor versions, fill the variables // // first find the highest Major version, then the highest minor version of that version $version = `match "_[vV][0-9]+" $file`; // major Version in string format int $v = `match "[0-9]+$" $version`; if ($v > $vW) $vW = $v; } $maxMajVersionWork = ("_v" + ttPadNumber($vW, 2)); //only process the highest major version and find the highest minorVersion: // for ($file in $filesInWork) { if (`gmatch $file ("*" + $maxMajVersionWork + "*")`){ $version = `match "_[0-9]+" $file`; // minor Version in string format of highestMajorVersion int $v = `match "[0-9]+$" $version`; if ($v > $vw) $vw = $v; } } $maxMinVersionWork = ("_" + ttPadNumber($vw, 2)); //ok, MaxFileVersionWork is teh product of both $maxFileVersionWork = ($maxMajVersionWork + $maxMinVersionWork); print ("$maxFileVersionWork: " + $maxFileVersionWork + "\n"); print ("$maxMinVersionWork: " + $maxMinVersionWork + "\n"); print ("$maxMajVersionWork: " + $maxMajVersionWork + "\n"); // highest version in WORK - increase MINOR version // get last digits $i = $vw; $i++; $minV = ttPadNumber($i, 2); $returnString = `substitute "[0-9]+$" $maxFileVersionWork $minV`; print ("incremented File version: " + $returnString + "\n"); } else { //warning "error in script pubGetNextFileVersion (labScripts)\n"; $returnString = "_v01_01"; } $returnString = `substitute "_V" $returnString "_v"`; return ("" + $returnString); } else { //print "fileName was empty\n"; return "_v01_01"; } } global proc int boldIncrementSave() { // UPDATE TO CHECK IF CURRENT FILE IS IN SHOTDIR // incremental save (without destroying undo history) // string $fileName, $newSceneName, $version, $sceneDir, $sceneName, $fullName; int $error; // get current sceneName/path // $sceneName = `file -q -sceneName`; $sceneDir = dirname( $sceneName ); int $error = `boldCheckForUnknownNodes`; if (!$error){ // rename open file to incremented minorVersion +1 // first lets determine and increment the name string $fileType = fileExtension($sceneName); // determine file type/extension string $type; int $errorCatch = 0; if ($fileType == "mb"){ $type = "mayaBinary"; $errorCatch = 1; } else if ($fileType == "ma"){ $type = "mayaAscii"; $errorCatch = 1; } if ($errorCatch){ if (`match "_[vV][0-9]+_[0-9]+..." $sceneName` != ""){ // here the changes since the last save are transferred to the new scene and the old is unchanged since it was // initially saved $fileName = `substitute "_[vV][0-9]+_[0-9]+..." $sceneName ""`; //remove version $fileName = `substitute ".*/" $fileName ""`; //remove directories // determine next version // $version = `boldGetNextFileVersion $fileName $sceneDir`; string $newName = ($sceneDir + "/" + $fileName + $version + "." + $fileType); file -rename $newName; print ("renaming file to: " + $newName + "\n"); // save current scene // file -f -save -options "v=0" -type $type; string $cmd = ("file -f -save -options \"v=0\" -type " + $type); evalEcho($cmd); if (`optionVar -exists "RecentFilesList"`){ // remove first item optionVar -removeFromArray "RecentFilesList" 0; //print "removed first array in optionVar RecentFilesList\n"; // add the new fileName to the RecentFileList optionVar -stringValueAppend "RecentFilesList" $newName; //print "added array current file to optionVar RecentFilesList\n"; } print ("preserving File Type of " + $type + "\n"); print ("saving safety Backup file " + $newName + "\n"); $error = 0; } else { warning "File does not conform to versioning convention, saving aborted\n"; $error = 1; } } else { warning "FILE NOT SAVED - error in precedure pubIncrementSave\n"; $error = 1; } } else { warning "FILE NOT SAVED - File not in current working directory\n"; $error = 1; } return $error; }