# -= ml_convertRotationOrder.py =- # __ by Morgan Loomis # ____ ___ / / http://morganloomis.com # / __ `__ \/ / Revision 5 # / / / / / / / 2018-02-17 # /_/ /_/ /_/_/ _________ # /_________/ # # ______________ # - -/__ License __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Copyright 2018 Morgan Loomis # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the # Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # ___________________ # - -/__ Installation __/- - - - - - - - - - - - - - - - - - - - - - - - - - # # Copy this file into your maya scripts directory, for example: # C:/Documents and Settings/user/My Documents/maya/scripts/ml_convertRotationOrder.py # # Run the tool in a python shell or shelf button by importing the module, # and then calling the primary function: # # import ml_convertRotationOrder # ml_convertRotationOrder.ui() # # # __________________ # - -/__ Description __/- - - - - - - - - - - - - - - - - - - - - - - - - - - # # Change the rotation order of an object while preserving animation. When you # want to change the rotation order of a control after you've already animated, or # don't want to alter the pose of an object. # # ____________ # - -/__ Usage __/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Run the UI. Select the objects with rotation orders you want to change, and # press the button for the desired rotation order. # # # ___________________ # - -/__ Requirements __/- - - - - - - - - - - - - - - - - - - - - - - - - - # # This script requires the ml_utilities module, which can be downloaded here: # https://raw.githubusercontent.com/morganloomis/ml_tools/master/ml_utilities.py # # __________ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /_ Enjoy! _/- - - __author__ = 'Morgan Loomis' __license__ = 'MIT' __revision__ = 5 __category__ = 'animation' import maya.cmds as mc from maya import OpenMaya try: import ml_utilities as utl utl.upToDateCheck(32) except ImportError: result = mc.confirmDialog( title='Module Not Found', message='This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.', button=['Download Module','Cancel'], defaultButton='Cancel', cancelButton='Cancel', dismissString='Cancel' ) if result == 'Download Module': mc.showHelp('http://morganloomis.com/tool/ml_utilities/',absolute=True) ROTATE_ORDERS = ['xyz', 'yzx','zxy','xzy','yxz','zyx'] _BUTTON = dict() def ui(): ''' User interface for convert rotation order ''' with utl.MlUi('ml_convertRotationOrder', 'Convert Rotation Order', width=400, height=140, info='''Select objects to convert and press button for desired rotation order. Use the "Get Tips" button to see suggestions for a single object on the current frame.''') as win: mc.button(label='Get tips for selection', command=loadTips, annotation='') mc.scrollField('ml_convertRotationOrder_nodeInfo_scrollField', editable=False, wordWrap=True, height=60) mc.rowColumnLayout(numberOfColumns=2, columnWidth=[(1,100), (2,400)], columnAttach=[2,'both',1]) for each in ROTATE_ORDERS: _BUTTON[each] = win.buttonWithPopup(label=each, command=globals()[each], annotation='Convert selected object rotate order to '+each+'.', shelfLabel=each) mc.textField('ml_convertRotationOrder_'+each+'_textField', editable=False) resetTips() def loadTips(*args): sel = mc.ls(sl=True) if not len(sel) == 1: OpenMaya.MGlobal.displayWarning('Please select a single object.') return resetTips() ro = ROTATE_ORDERS[mc.getAttr(sel[0]+'.rotateOrder')] nodeName = mc.ls(sl=True, shortNames=True)[0] infoText = 'This object is ' tol = gimbalTolerence(sel[0]) if tol < 0.1: infoText += 'not currently gimballing' else: if tol < 0.5: infoText += 'only ' infoText += str(int(tol*100)) infoText+='% gimballed' #test all rotation orders and find the lowest value rotOrderTests = testAllRotateOrdersForGimbal(sel[0]) lowest = sorted(rotOrderTests)[0] #find the lower of the two worldspace options lowestWS = 1 for each in rotOrderTests[2:4]: if each < lowestWS: lowestWS = each #determine if it's a worldspace control ws = isWorldSpaceControl(sel[0]) if ws: infoText += ", and it looks like it's a worldspace control." else: infoText+='.' for t, r in zip(rotOrderTests, ROTATE_ORDERS): if r == ro: continue text = str(int(t*100)) + '% Gimballed. ' if ws: if r.endswith('y') and t == lowestWS: #lowest worldspace option is reccomended text += '<-- [RECOMMENDED]' elif lowest