{"id":204,"date":"2014-08-06T09:57:53","date_gmt":"2014-08-05T23:57:53","guid":{"rendered":"http:\/\/alrichardson.com\/?p=204"},"modified":"2014-08-06T09:57:53","modified_gmt":"2014-08-05T23:57:53","slug":"updated-save-tool","status":"publish","type":"post","link":"https:\/\/alrichardson.com\/?p=204","title":{"rendered":"Updated save tool!"},"content":{"rendered":"<p>I&#8217;ve updated the savetool to keep a master version of the file! I&#8217;m now refefing to it as an Up Save tool.<\/p>\n<pre class=\"lang:python decode:true \" >################################################################################################\r\n################################################################################################\r\n###                             Save new version of current scene                            ###\r\n###                                  By Alastair Richardson                                  ###\r\n###                                         May, 2013                                        ###\r\n###                               Intended for Maya Ascii files                              ###\r\n###          Use:                                                                            ###\r\n###             padding is the number of digits in the version number.                       ###\r\n###                                                                                          ###\r\n###             versionIndicator is the characters that come before                          ###\r\n###             the version number. May be _V or _v depending on your                        ###\r\n###             pipeline.                                                                    ###\r\n###                                                                                          ###\r\n###             fileCountNumbering can be set to True or False.                              ###\r\n###             If set to True, the next version number will be obtained                     ###\r\n###             by counting the number of files in the working folder.                       ###\r\n###             This method is unpredictable if folder contains additional                   ###\r\n###             files or folders.                                                            ###\r\n###                                                                                          ###\r\n###             If set to False, the next version number will be obtained                    ###\r\n###             using the current version number, can be risky if rolling                    ###\r\n###             to old versions is required.                                                 ###\r\n###                                                                                          ###\r\n################################################################################################\r\n################################################################################################\r\n \r\npadding = 3\r\nversionIndicator = '_v'\r\nfileCountNumbering = False\r\nmasterFileName = '_v000'\r\n \r\n################################################################################################\r\n###                                                                                          ###\r\n###                             Change script at your own risk                               ###\r\n###                                                                                          ###\r\n################################################################################################\r\nimport maya.cmds as cmds\r\nfrom pymel.core import *\r\nimport maya.OpenMaya as om\r\nimport os\r\n \r\ndef saveNewVer():\r\n    a = ''\r\n    b = ''\r\n    # find directory\r\n    currentDir = cmds.file( query = True, location = True )\r\n    splitDir = currentDir.split('\/')\r\n    length = len(splitDir)\r\n    lessOne = length - 1\r\n    shortDir = splitDir[0:lessOne]\r\n    directoryToOpen = '\/'.join(shortDir)\r\n    # create next version number of file\r\n    if fileCountNumbering == True :\r\n        # find the next version based on number of files on directory\r\n        currentFileName = splitDir[length -1]\r\n        versionSpilt = currentFileName.split(versionIndicator)\r\n        currentName = versionSpilt[0]\r\n        files = os.listdir( directoryToOpen )\r\n        mayaAscii = []\r\n        for i in files:\r\n            try:\r\n                a,b = i.split('.')\r\n            except:\r\n                print i + ' has no extension'\r\n            if b == 'ma':\r\n                mayaAscii.append(i)\r\n            else:\r\n                print str(i) + ' is not a Maya ASCII'\r\n        nextVersion =  len(mayaAscii) + 1  \r\n    else:\r\n        # find version by disecting current file name at _v\r\n        currentFileName = splitDir[length -1]\r\n        versionSpilt = currentFileName.split(versionIndicator)\r\n        sansMA = versionSpilt[1].split('.')\r\n        currentVersion = sansMA[0]\r\n        currentName = versionSpilt[0]\r\n        nextVersion = int(currentVersion) + 1\r\n    # do the saving\r\n    newDirName = directoryToOpen + '\/' + currentName + versionIndicator + str(nextVersion).zfill(padding)\r\n    Mel.eval( \"source addRecentFile.mel\" )\r\n    Mel.eval('addRecentFile \"%s\" \"%s\";' % (newDirName + '.ma', 'mayaAscii'))\r\n    masterName = directoryToOpen + '\/' + currentName + masterFileName\r\n    cmds.file( rename = masterName )\r\n    cmds.file( save = True )\r\n    cmds.file( rename = newDirName )\r\n    cmds.file( save = True )\r\n    om.MGlobal.displayInfo( 'saved to ' + newDirName )\r\nsaveNewVer()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve updated the savetool to keep a master version of the file! I&#8217;m now refefing to it as an Up Save tool. ################################################################################################ ################################################################################################ ### Save new version of current scene ### ### By Alastair Richardson ### ### May, 2013 ### ### Intended for Maya Ascii files ### ### Use: ### ### padding is the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-maya"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":1,"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}