Download Here: MEL Script - jgIncrementalSave.mel
// **********************************************************
// Automatically Increments A Saved Maya File
global proc jgIncrementalSave () {
// Scene File Name
string $sceneFile = `file -q -sn` ;
// Get File Extension
string $extension = `fileExtension $sceneFile` ;
// Remove Extension
string $fileNameNoExt ;
if($extension == "mb" || $extension == ".ma") {
// Tokenize Filename
string $buffer[] ;
tokenize $sceneFile "." $buffer ;
// Recompile Scenename Without Extension
for($i = 0; $i < (size($buffer)-1); $i++) { $fileNameNoExt = $fileNameNoExt + $buffer[$i] ; } } else { // Error Check error "Open file isn't .mb or .ma, please save before incrementing." ; } // Extract Name And Current Version Using Regex string $nameWithNoVersion = `match ".*[^0-9]" $fileNameNoExt` ; string $currentVersion = `match "[0-9]+$" $fileNameNoExt` ; // Check For Integer, Add One If None if($currentVersion == "") $currentVersion = "00" ; // Increment Version int $int = $currentVersion ; $int++ ; // Pad Digits If Needed int $beforeCount = size($currentVersion) ; string $incVersion = $int ; int $afterCount = size($incVersion) ; if($beforeCount > $afterCount) {
while($beforeCount > $afterCount) {
$incVersion = ("0"+$incVersion) ;
$afterCount = size($incVersion) ;
}
}
// Make New Filename
string $newFileName = ($nameWithNoVersion+$incVersion+"."+$extension) ;
// Save It
file -rename $newFileName ;
file -f -save ;
// Add To Recent File List
if($extension == "mb") catch(`addRecentFile $newFileName "mayaBinary"`) ;
if($extension == "ma") catch(`addRecentFile $newFileName "mayaAscii"`) ;
// Finish
print ("Saved as "+$newFileName+"\n") ;
} jgIncrementalSave ;
As always if you find any bugs, have any questions about the code, or would like to make suggestions please leave a comment below.
Recently, I was using jgIncrementalSave to save the Blake 1.6 rig (available on Highend) and I got the //Error: current file isn't .mb or .ma, please save before incrementing.
ReplyDeleteIt was definitely saved as a .ma.
This only happened when it was saved as .ma, .mb works fine. Saving back to .ma after saving it as .mb still does not work.
Oh yeah, and this was on Windows 7, Maya 2011.
ReplyDeleteThanks man, I'll look into this.
ReplyDeleteThe bug is in the IF statement of the # // Remove Extension. There should be no period before .ma . Works perfectly once you remove the dot :)
ReplyDeleteCode in Question => # if($extension == "mb" || $extension == ".ma") {
Nice work
what is the advantage to using maya's native incremental save feature?
ReplyDeletethanks
Nope, not working with maya2011. Undeclared variables.
ReplyDeletethanks a lot! works perfect in maya 2013
ReplyDeleteWorking Maya 2013.
ReplyDeleteAdd for hotkey is perfect
Hi mate, this is great however our format is SceneName_v001_Initials_Comments.mb
ReplyDeletewhat would you recommend changing to make this work? Is there perhaps a way to make it work for different incremental formats? Cheers in advance!