Last active
December 13, 2018 06:51
-
-
Save Onefabis/25ff0ccdfcc9dbc547b47834b71a0f18 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
import maya.cmds as cmds | |
import re | |
import maya.mel as mel | |
def MSpress(): | |
global initTS | |
initTS = cmds.timerX() | |
def MSrelease(): | |
global initTS | |
hTime = cmds.timerX(st=initTS) | |
if hTime > 0.4: | |
scenenm = cmds.file( q=1, sn=1 ) | |
spltname = scenenm.rsplit("/", 1) | |
m = re.search(r'\d+$', spltname[1][:-3] ) | |
# if the string ends in digits m will be a Match object, or None otherwise. | |
xName = 1 | |
clName = '' | |
nName = '' | |
if m is not None: | |
xName = xName + int ( m.group() ) | |
clName = re.sub(m.group()+'$', '', spltname[1][:-3]) | |
nName = clName + "%02d" % ( xName ) + spltname[1][-3:] | |
else: | |
nName = spltname[1][:-3] + '_' + "%02d" % ( xName ) + spltname[1][-3:] | |
cmds.file( rename=spltname[0] + '/' + nName ) | |
cmds.file( f=1, s=1 ) | |
else: | |
mel.eval('checkForUnknownNodes(); FileMenu_SaveItem') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment