pyMel

Saving time

I spent today putting finishing touches on a script that saves a new version of the current scene. and a button icon to go with!
ALRsaveVer
Grab the script here and pop it on your shelf.

################################################################################################
################################################################################################
###                             Save new version of current scene                            ###
###                                  By Alastair Richardson                                  ###
###                                         May, 2013                                        ###
###                               Intended for Maya Ascii files                              ###
###          Use:                                                                            ###
###             padding is the number of digits in the version number.                       ###
###                                                                                          ###
###             versionIndicator is the characters that come before                          ###
###             the version number. May be _V or _v depending on your                        ###
###             pipeline.                                                                    ###
###                                                                                          ###
###             fileCountNumbering can be set to True or False.                              ###
###             If set to True, the next version number will be obtained                     ###
###             by counting the number of files in the working folder.                       ###
###             This method is unpredictable if folder contains additional                   ###
###             files or folders.                                                            ###
###                                                                                          ###
###             If set to False, the next version number will be obtained                    ###
###             using the current version number, can be risky if rolling                    ###
###             to old versions is required.                                                 ###
###                                                                                          ###
################################################################################################
################################################################################################

padding = 3
versionIndicator = '_v'
fileCountNumbering = True

################################################################################################
###                                                                                          ###
###                             Change script at your own risk                               ###
###                                                                                          ###
################################################################################################
import maya.cmds as cmds
from pymel.core import *
import maya.OpenMaya as om
import os

def saveNewVer():
    # find directory
    currentDir = cmds.file( query = True, location = True )
    splitDir = currentDir.split('/')
    length = len(splitDir)
    lessOne = length - 1
    shortDir = splitDir[0:lessOne]
    directoryToOpen = '/'.join(shortDir)
    # create next version number of file
    if fileCountNumbering == True :
        # find the next version based on number of files on directory
        currentFileName = splitDir[length -1]
        versionSpilt = currentFileName.split(versionIndicator)
        currentName = versionSpilt[0]
        files = os.listdir( directoryToOpen )
        mayaAscii = []
        for i in files:
            try:
                a,b = i.split('.')
            except:
                print i + ' has no extension'
            if b == 'ma':
                mayaAscii.append(i)
            else:
                print str(i) + ' is not a Maya ASCII'
        nextVersion =  len(mayaAscii) + 1   
    else:
        # find version by disecting current file name at _v
        currentFileName = splitDir[length -1]
        versionSpilt = currentFileName.split(versionIndicator)
        sansMA = versionSpilt[1].split('.')
        currentVersion = sansMA[0]
        currentName = versionSpilt[0]
        nextVersion = int(currentVersion) + 1
    # do the saving
    newDirName = directoryToOpen + '/' + currentName + versionIndicator + str(nextVersion).zfill(padding)
    Mel.eval( "source addRecentFile.mel" )
    Mel.eval('addRecentFile "%s" "%s";' % (newDirName + '.ma', 'mayaAscii'))
    cmds.file( rename = newDirName )
    cmds.file( save = True )
    om.MGlobal.displayInfo( 'saved to ' + newDirName )
saveNewVer()