// Creation Date: Feb 17 1998 // Author: rns // http://www.uberware.net/mel/ // // Procedure Name: // confirmProjChange // // Description: // A script job that runs when a file is opened. If the file is in // a new project directory, it confirms if the user should change // the current project to the new one. // // Version 1.3: Sep 10 1999 // No longer requires osTest.mel, but now requires maya 2.0! // Fixed NT temp directory opening bug // // Version 1.2: Aug 17 1999 // if you're loading a crash file from the temp directory it doesn't // ask you // // Version 1.1: Aug 6 1999 // works with both IRIX and NT // requires the osTest.mel script // // Use and Modify at your own risk. global proc confirmProjChange() { string $sceneName = `file -q -sceneName`; string $curWorkspace = `workspace -q -rd`; string $snBuf[]; string $wsBuf[]; int $lastSN; int $lastWS; int $usingNT = (`about -os` == "nt") ; // not necessary, but nice string $sep = ($usingNT ? "\\" : "/"); $lastSN = tokenize($sceneName, "/\\", $snBuf); $lastWS = tokenize($curWorkspace, "/\\", $wsBuf); if ($lastSN>1) // assume we're starting up with a blank scene { // this is the check for loading a crash file from the temp dir if ($usingNT) { int $return = true; // on NT, the environment variable is "TEMP" (or "TMP" but who cares?) string $tmpDir = `getenv "TEMP"`; // have to use this sort of test cuz file -q uses / and $TEMP stores \ string $tmpBuf[]; int $lastTmp = tokenize($tmpDir, "/\\", $tmpBuf); for ($n=0; $n<$lastTmp; $n++) if ($tmpBuf[$n]!=$snBuf[$n]) { $return = false; break; } if ($return) return; } else { // on IRIX we're hoping for "TMPDIR" string $tmpDir; $tmpDir = `getenv "TMPDIR"`; if (!size($tmpDir)) $tmpDir = "/usr/tmp"; // reasonable default value if (substring ($sceneName,1,size($tmpDir)) == $tmpDir) return; } // otherwise check for opening in a different directory if ($snBuf[$lastSN-3] != $wsBuf[$lastWS-1]) { // ask the user. woo hoo! string $msg = "The file '"+$snBuf[$lastSN-1]+ "' is not in the current project '"+$wsBuf[$lastWS-1]+ "'.\nChange to project '"+$snBuf[$lastSN-3]+"'?"; string $return = `confirmDialog -t Warning -m $msg -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No" -dismissString "No"`; if (!strcmp($return, "Yes")) { // build the path string $path; if (!$usingNT) $path += "/"; $path += $snBuf[0]; for ($i = 1; $i <= $lastSN-3; $i++) { $path += $sep + $snBuf[$i]; } print ("// Setting project to " + $path + "\n"); // this sets the project. this is ripped from the maya // scripts and is amazingly more difficult than it should be. workspace -o $path; np_resetBrowserPrefs; if (`window -ex projectViewerWindow`) { pv_resetWorkspace; // Force the layout to be redone. } workspace -dir `workspace -q -rd`; } } } }