Tuesday, February 8, 2011

Save Incremental Version



Here's a small code to save an Incremental version of your maya file, so basically, no need to go to Save-As-> type the Name Again, just Copy the code in a MEL Shelf button: and every-time you need make an Incremental save, hit that Button.
  1. global proc incrementalSave()
  2. {
  3. string $f=`file -q -sn`; // get file name
  4. string $ft[]=`file -q -typ`; // file type (mayaAscii, etc.)

  5. if ($f!="")
  6. {

  7. // * extracting base filename (path/basename) and version number *

  8. string $n[],$ext="";

  9. if (tokenize($f,".",$n)) $ext=$n[size($n)-1];
  10. if (size($n)>1) $f=substring($f,1, size($f)-size($ext)-1 );
  11. if ($ext!="") $ext=("."+$ext);

  12. int $x=0, $m=1, $v=0, $d=0, $w=1;

  13. while($x==0)
  14. {
  15. string $e=substring($f,size($f),size($f)); // last character (as string)

  16. if (gmatch($e,"[0-9]")) // last character was a number?
  17. {
  18. $v+=($m*(int)$e);
  19. $m*=10;
  20. $d++; // (count number of digits)
  21. $f=substring($f,1,size($f)-1); // chop last character
  22. }
  23. else $x=1;
  24. }

  25. // * renaming current file (with incremented version number) *

  26. $v++; // increment version number
  27. string $vs=("000000000"+(string)$v);

  28. if ($d<1) $d=2; if ($d>8) $d=8;

  29. $vs=substring($vs,size($vs)-$d+1,size($vs));

  30. $f=($f+$vs+$ext);

  31. if (`confirmDialog -t "Save [+]" -m ("Save Scene As '"+$f+"' ?") -b "Ok" -b "Cancel" -cb "Cancel" -ds "Cancel"`!="Cancel")
  32. {
  33. file -rename $f;

  34. if (`file -q -ex $f`)
  35. {
  36. if (`confirmDialog -t "File Already Exists" -m ("Overwrite already existing file '"+$f+"'?") -b "Yes" -b "No" -cb "No" -ds "No"`!="Yes")
  37. $w=0;
  38. }

  39. if ($w)
  40. {
  41. //FileMenu_SaveItem;
  42. warning("projMan: Saving File...");
  43. evalEcho("file -save");
  44. addRecentFile($f,$ft[0]); // add to the recent files list
  45. }
  46. }
  47. }
  48. else projectViewer SaveAs;
  49. }
  50. incrementalSave;

No comments:

Post a Comment