Check out my portfolio and contact me.

Archive for the ‘Scripting’ Category

Incremental Save Script Maya Python

Posted on: August 10th, 2013 by Redd 1 Comment

I came up with a nice little incremental save script in Maya for those that want to control when they incrementally save instead of Maya’s incremental solution where if you enable this action it will save out a new version of your file each time you save. This could be troublesome when you are working with very large files and don’t want your drives filled up with saves don’t necessarily need to be incremented.

from pymel.core import *
import os

def incSave():
    path = sceneName()
    fileName = path.split('/')[-1].partition(".")[0]
    newFileName = fileName+"_0001"+".ma"
    incSaveFolder = "incrementalSave"
    fileFolder = os.path.abspath(os.path.join(path, os.pardir))
    incSaveFolderPath = os.path.join(fileFolder,incSaveFolder)
    projectSaveFolder = os.path.join(incSaveFolderPath, fileName)
    incSaveFilePath = os.path.join(projectSaveFolder, newFileName)
    
    if os.path.exists(incSaveFilePath):
        savedFiles = os.listdir(projectSaveFolder)
        savedFiles.sort()
        incFiles = []
        for i in savedFiles:
            if fileName in i:
                incFiles.append(i)
        lastFile = incFiles[len(incFiles)-1]
        name = lastFile.partition(".")[0]
        newName = name[:-4]+(str(int(name[-4:])+1).zfill(4))+".ma"
        incSaveFilePath = os.path.join(projectSaveFolder, newName)
        system.saveAs(incSaveFilePath)
        system.saveAs(path)
    else:
        os.makedirs(projectSaveFolder)
        system.saveAs(incSaveFilePath)
        system.saveAs(path)

incSave()

As always I hope this helps people out and feel free to leave any comments or suggestions to improve this script. as a warning I have someone testing this out for me and I have made small changes to it and I will make changes to it on an as needed basis.