View Full Version : Incremental Save script V1.0

09 September 2007, 07:16 PM
Hey guys I'm pretty new to mel and I've been fooling around with it and thought i'd share this. Its an incremental save script that saves your current file up a version and places the old file in a "bak" folder where your original scene file was stored.

Rules: You need to name your scene in a scenename001.extention
in otherwords the last 3 characters before the extention need to be numbers.

if its not set up right it will error out and tell you to rename your scene. :)

I know that there is an incremental save built into maya but this avoids the annoying double folders and such that are associated with that. Any thoughts suggestions or bug findings are welcome! As always use at your own risk.


//SPJ_saveIncremental 1.0

// This script takes the current scene file you have open and
// copies the last saved version into a folder called "bak" and then renames
// the current scene to a version up and saves it. this works on maya 8.5 but
// there is a confirmed breaking of the code on maya 6.5. not sure about other
// versions. Use this script at your own risk.
// Rules: Your scene name has to have 3 numbers before the .ma or .mb extention. i.e.:

global proc spj_saveIncremental()


//get current file name//
string $currentFilePath = `file -q -sceneName`;

// Set up the mb_ma extention
string $fullFilename = `basename $currentFilePath ""`;
string $extOnly = endString($fullFilename, 3);

//get current file path without the file name
string $currentFiledir = dirname($currentFilePath);

//create the final upped version name

string $NameOnly = `basenameEx $currentFilePath`;
string $numbersOnly = endString($NameOnly, 3);

$validString = isValidString($numbersOnly,

if ($validString == "0")
error "The scene needs to be named in a scenename001.extention format";

// Get the name without the version number
$stringSize = size($NameOnly);
float $stringSizefloat = $stringSize;
float $stringSizefloat = $stringSizefloat - 3;
string $lettersOnly = `substring $NameOnly 1 $stringSizefloat`;

// Get the version numbers only and up the version by 1
string $numbersOnly = "." + $numbersOnly;
float $num = $numbersOnly;
float $num = $num + .001;
string $numbersOnly = $num;
string $numbersOnly = substituteAllString($numbersOnly, ".", "");
string $numbersOnly = `substring $numbersOnly 2 4`;

//fix decimal problem//

$validString = isValidString($numbersOnly,

if ($validString == "0")
$numbersOnly = $numbersOnly + "0";

// create the final name + dir path
string $Finalname = $currentFiledir + "/" + $lettersOnly + $numbersOnly + $extOnly;

//make backup directory
string $creationdir = $currentFiledir + "/bak";
sysFile -makeDir $creationdir;

//copy orginal file to the bak folder and rename it
string $sceneName = basename( $currentFilePath, "" );
string $versionupfile = $currentFiledir + "/bak/" + $sceneName;
sysFile -copy $versionupfile $currentFilePath;

//Save and rename
file -save;
file -rename $Finalname;
sysFile -rename $Finalname $currentFilePath;


Robert Bateman
09 September 2007, 03:58 PM
I prefer something such as subversion (or Tortoise SVN if you are on windows) for this sort of thing. Works better with Maya Ascii files generally....

09 September 2007, 04:05 PM
isn`t this the same as the incremental save option?

09 September 2007, 06:09 AM
Thanks for the feedback guys! :) It is I admit a personal challenge for me more than anything. Just learning some basic mel and all. But it does differ from the incremetal save in maya in that It doesn't stack each saved file under multiple folders but instead keeps them all in one. It is just basic functionality for now but I like to view it as a good starting point for me to expand from :) I've not heard of subversion Robert Bateman I'll have to check that out.

CGTalk Moderation
09 September 2007, 06:09 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.