Skip to content

Instantly share code, notes, and snippets.

@berniebernie
Last active October 19, 2015 22:29
Show Gist options
  • Select an option

  • Save berniebernie/015da6b46ef69e3e35d1 to your computer and use it in GitHub Desktop.

Select an option

Save berniebernie/015da6b46ef69e3e35d1 to your computer and use it in GitHub Desktop.
saves incrementally with a padding of 2, prompts for the name http://i.imgur.com/2GeQRpR.jpg
proc incrementAndSave(){
//takes the current scene, increments (or adds '01' suffix if none found). Padding set to 2
//so many regexes because I suck at this
string $path = `file -q -loc`;
$path = `match "^.*/" $path`;
string $file = `file -q -sn -shn`;
$ext = fileExtension($file);
$file = `match "^[^\.]*" $file`;
string $suffix = `match "[0-9]+$" $file`;
$file = `match ".*[^0-9]" $file`;
int $suff = 1;
if($suffix != ""){
$suff = $suffix;
$suff++;
}
$suffix = ($suff<10)?"0"+$suff:$suff;
$fileprompt = `promptDialog -text ($file+$suffix+"."+$ext) -title "Save as" -message "New file name:" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel"`;
if($fileprompt == "OK"){
$scene = `promptDialog -q -text`;
$type = (`tolower $ext` == "ma")?"mayaAscii":"mayaBinary";
file -rename ($path+$scene); file -save -type $type;
}
}
incrementAndSave;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment