{"id":43,"date":"2013-05-09T16:33:56","date_gmt":"2013-05-09T06:33:56","guid":{"rendered":"http:\/\/alrichardson.com\/?p=43"},"modified":"2013-07-01T23:23:49","modified_gmt":"2013-07-01T13:23:49","slug":"43","status":"publish","type":"post","link":"https:\/\/alrichardson.com\/?p=43","title":{"rendered":"Saving time"},"content":{"rendered":"<p>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!<br \/>\n<a href=\"https:\/\/alrichardson.com\/wp-content\/uploads\/2013\/05\/ALRsaveVer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-44\" alt=\"ALRsaveVer\" src=\"https:\/\/alrichardson.com\/wp-content\/uploads\/2013\/05\/ALRsaveVer.png\" width=\"32\" height=\"32\" \/><\/a><br \/>\nGrab the script here and pop it on your shelf.<\/p>\n<pre class=\"font-size:10 line-height:12 nums:false 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 = True\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    # 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    cmds.file( rename = newDirName )\r\n    cmds.file( save = True )\r\n    om.MGlobal.displayInfo( 'saved to ' + newDirName )\r\nsaveNewVer()<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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! Grab the script here and pop it on your shelf. ################################################################################################ ################################################################################################ ### Save new version of current scene ### ### By Alastair Richardson ### ### May, 2013 ### ### [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,11,5,7],"tags":[],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-coding","category-maya","category-pymel","category-python","category-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/43","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=43"}],"version-history":[{"count":14,"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/alrichardson.com\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alrichardson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}