Last active
April 4, 2019 18:06
-
-
Save Onefabis/b1e0eb4998cfa49313a9015cdf232d91 to your computer and use it in GitHub Desktop.
Saves the new version of the file with right numeric postfix. For instance, ex.ma will be saved as ex_01.ma. ex_02.ma will be saved as ex_03.ma, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
_______________________________________ | |
Name: magicSave | |
Version: 1.1 | |
Author: Alexander Smirnov | |
e-mail: [email protected] | |
site: fabis.xyz | |
_______________________________________ | |
Instructions: | |
Put the script into the Maya script folder, for example: | |
C:\Users\ USERNAME \Documents\maya\ MAYAVERSION \scripts | |
Assign the code to the hotkey press (for instance Ctrl+S - press): | |
import magicSave; magicSave.run() | |
and the code to the hotkey release (for instance Ctrl+S - release): | |
import magicSave; magicSave.save() | |
If you press the hotkey shortly (less than 0.4 sec.) it will save the scene in a default way, if you hold the key longer (more than 0.4 sec.) it will save it in the next way: | |
1. If existing scene called 'Scene.ma', it will save it as 'Scene_01.ma' | |
2. If existing scene called 'Scene_01.ma', it will save it as 'Scene_02.ma', etc. | |
Note that if you will save the current scene with the name 'Scene_01.ma', but in this directory exists similar files with postfixes, till, for instance 'Scene_05.ma', | |
it will show you the prompt dialog window, where it will ask you to overwrite the next version 'Scene_02.ma', save the last scene as 'Scene_06.ma' or cancel the operation. | |
_______________________________________ | |
''' | |
import maya.cmds as mc | |
import maya.mel as mel | |
import re | |
import os | |
def run(): | |
global mSaveTimer | |
mSaveTimer = mc.timerX() | |
def save(): | |
global mSaveTimer | |
checkTime = mc.timerX(st=mSaveTimer) | |
if checkTime<0.4: | |
mel.eval( 'checkForUnknownNodes(); FileMenu_SaveItem' ) | |
else: | |
sn = mc.file( q=1, exn=1 ).rsplit( '/', 1 ) | |
m = re.search( r'\d+$', sn[1][:-3] ) | |
xName = 1 | |
nName = '' | |
finName = None | |
if m: | |
nName = re.sub( m.group() + '$', '', sn[1][:-3] ) + '%02d' % ( int( m.group() ) + 1 ) + sn[1][-3:] | |
else: | |
nName = sn[1][:-3] + '_' + '%02d' % ( xName ) + sn[1][-3:] | |
if os.path.exists(sn[0] + '/' + nName): | |
cName = nName | |
while os.path.exists(sn[0] + '/' + cName): | |
sn = (sn[0] + '/' + cName).rsplit( '/', 1 ) | |
m = re.search( r'\d+$', sn[1][:-3] ) | |
cName = re.sub( m.group() + '$', '', sn[1][:-3] ) + '%02d' % ( int( m.group() ) + 1 ) + sn[1][-3:] | |
result = mc.promptDialog( title='Save scene', tx=cName, message='Next version(s) already exists, save the last one?:', button=[ 'Save last', 'Overwrite next', 'Cancel'], defaultButton='Save as last', cancelButton='Cancel', dismissString='Cancel') | |
if result == 'Save last': | |
finName = mc.promptDialog( query=1, text=1) | |
elif result == 'Overwrite': | |
finName = nName | |
else: | |
finName = nName | |
if finName: | |
mc.file( rename=sn[0] + '/' + finName ) | |
mc.file( f=1, s=1 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment