Skip to content

Commit 4ad3d8c

Browse files
committed
update to isolateView, better maya version handling, spaceSwitch bug fix
1 parent 44a2914 commit 4ad3d8c

File tree

2 files changed

+63
-52
lines changed

2 files changed

+63
-52
lines changed

ml_puppet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# / __ `__ \/ / Licensed under Creative Commons BY-SA
66
# / / / / / / / http://creativecommons.org/licenses/by-sa/3.0/
77
# /_/ /_/ /_/_/ _________
8-
# /_________/ Revision 17, 2017-06-04
8+
# /_________/ Revision 17, 2017-06-13
99
# _______________________________
1010
# - -/__ Installing Python Scripts __/- - - - - - - - - - - - - - - - - - - -
1111
#
@@ -53,7 +53,7 @@
5353

5454
try:
5555
import ml_utilities as utl
56-
utl.upToDateCheck(29)
56+
utl.upToDateCheck(30)
5757
except ImportError:
5858
result = mc.confirmDialog( title='Module Not Found',
5959
message='This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.',
@@ -688,6 +688,7 @@ def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
688688
locators = []
689689
values = []
690690
for node in nodes:
691+
691692
ssData = getSpaceSwitchData(node)
692693
if not ssData:
693694
continue
@@ -714,8 +715,7 @@ def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
714715
#flip locator if we're going to or from a mirrored space
715716
if hasFlippedParent(node):
716717
mc.setAttr(locator+'.rotateX', mc.getAttr(locator+'.rotateX') + 180)
717-
718-
matchLocators.append(locator)
718+
719719
parent = mc.listRelatives(node, parent=True)
720720
if parent:
721721
if mc.getAttr(parent[0]+'.scaleX') < 0:
@@ -1361,3 +1361,5 @@ def flipAnimation(nodes, *args):
13611361
# Revision 17: 2017-05-24 : search higher for mirrored nodes when matching
13621362
#
13631363
# Revision 17: 2017-06-04 : adding puppet settings attributes
1364+
#
1365+
# Revision 17: 2017-06-13 : space switch matching bug fix

ml_utilities.py

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# / __ `__ \/ / Licensed under Creative Commons BY-SA
66
# / / / / / / / http://creativecommons.org/licenses/by-sa/3.0/
77
# /_/ /_/ /_/_/ _________
8-
# /_________/ Revision 29, 2017-04-25
8+
# /_________/ Revision 30, 2017-06-13
99
# _______________________________
1010
# - -/__ Installing Python Scripts __/- - - - - - - - - - - - - - - - - - - -
1111
#
@@ -34,7 +34,7 @@
3434
__author__ = 'Morgan Loomis'
3535
__license__ = 'Creative Commons Attribution-ShareAlike'
3636
__category__ = 'animationScripts'
37-
__revision__ = 29
37+
__revision__ = 30
3838

3939
import maya.cmds as mc
4040
import maya.mel as mm
@@ -50,7 +50,8 @@
5050
icon_path = os.path.join(os.path.dirname(__file__),'icons').replace('\\','/')
5151
if os.path.isdir(icon_path) and icon_path not in os.environ['XBMLANGPATH']:
5252
os.environ['XBMLANGPATH'] = os.pathsep.join((os.environ['XBMLANGPATH'],icon_path))
53-
53+
54+
MAYA_VERSION = mm.eval('getApplicationVersionAsFloat')
5455

5556
def _showHelpCommand(url):
5657
'''
@@ -213,7 +214,7 @@ def createHotkey(command, name, description='', python=True):
213214
Open up the hotkey editor to create a hotkey from the specified command
214215
'''
215216

216-
if mm.eval('getApplicationVersionAsFloat')>2015:
217+
if MAYA_VERSION > 2015:
217218
print "Creating hotkeys currently doesn't work in the new hotkey editor."
218219
print "Here's the command, you'll have to make the hotkey yourself (sorry):"
219220
print command
@@ -229,7 +230,7 @@ def createHotkey(command, name, description='', python=True):
229230
mc.textField('HotkeyEditorDescriptionField', edit=True, text=description)
230231

231232
if python:
232-
if mm.eval('getApplicationVersionAsFloat') < 2013:
233+
if MAYA_VERSION < 2013:
233234
command = 'python("'+command+'");'
234235
else: #2013 or above
235236
mc.radioButtonGrp('HotkeyEditorLanguageRadioGrp', edit=True, select=2)
@@ -269,10 +270,10 @@ def createShelfButton(command, label='', name=None, description='',
269270
shelfTab = gShelfTopLevel+'|'+shelfTab
270271

271272
#add additional args depending on what version of maya we're in
272-
kwargs = dict()
273-
if mm.eval('getApplicationVersionAsFloat') >= 2009:
273+
kwargs = {}
274+
if MAYA_VERSION >= 2009:
274275
kwargs['commandRepeatable'] = True
275-
if mm.eval('getApplicationVersionAsFloat') >= 2011:
276+
if MAYA_VERSION >= 2011:
276277
kwargs['overlayLabelColor'] = labelColor
277278
kwargs['overlayLabelBackColor'] = labelBackgroundColor
278279
if backgroundColor:
@@ -435,7 +436,7 @@ def getHoldTangentType():
435436
return 'linear','linear'
436437
if tangentType=='step':
437438
return 'linear','step'
438-
if tangentType == 'plateau' or tangentType == 'spline' or mm.eval('getApplicationVersionAsFloat') < 2012:
439+
if tangentType == 'plateau' or tangentType == 'spline' or MAYA_VERSION < 2012:
439440
return 'plateau','plateau'
440441
return 'auto','auto'
441442

@@ -447,7 +448,7 @@ def getIcon(name):
447448
'''
448449

449450
ext = '.png'
450-
if mm.eval('getApplicationVersionAsFloat') < 2011:
451+
if MAYA_VERSION < 2011:
451452
ext = '.xpm'
452453

453454
if not name.endswith('.png') and not name.endswith('.xpm'):
@@ -632,14 +633,14 @@ def matchBake(source=None, destination=None, bakeOnOnes=False, maintainOffset=Fa
632633
OpenMaya.MGlobal.displayWarning('No attributes to bake!')
633634
return
634635

635-
duplicates = dict()
636-
keytimes = dict()
636+
duplicates = {}
637+
keytimes = {}
637638
constraint = list()
638-
itt = dict()
639-
ott = dict()
640-
weighted = dict()
641-
itw = dict()
642-
otw = dict()
639+
itt = {}
640+
ott = {}
641+
weighted = {}
642+
itw = {}
643+
otw = {}
643644
#initialize allKeyTimes with start and end frames, since they may not be keyed
644645
allKeyTimes = [start,end]
645646
for s,d in zip(source,destination):
@@ -656,12 +657,12 @@ def matchBake(source=None, destination=None, bakeOnOnes=False, maintainOffset=Fa
656657

657658
#set up our data dictionaries
658659
duplicates[d] = dup
659-
keytimes[d] = dict()
660-
itt[d] = dict()
661-
ott[d] = dict()
662-
weighted[d] = dict()
663-
itw[d] = dict()
664-
otw[d] = dict()
660+
keytimes[d] = {}
661+
itt[d] = {}
662+
ott[d] = {}
663+
weighted[d] = {}
664+
itw[d] = {}
665+
otw[d] = {}
665666

666667
#if we're baking on ones, we don't need keytimes
667668
if not bakeOnOnes:
@@ -811,10 +812,8 @@ def renderShelfIcon(name='tmp', width=32, height=32):
811812

812813
mc.setAttr('defaultRenderGlobals.currentRenderer', 'mayaSoftware', type='string')
813814

814-
mayaVersion = mm.eval('getApplicationVersionAsFloat')
815-
816815
imageFormat = 50 #XPM
817-
if mayaVersion >= 2011:
816+
if MAYA_VERSION >= 2011:
818817
imageFormat = 32 #PNG
819818

820819
mc.setAttr('defaultRenderGlobals.imageFormat', imageFormat)
@@ -996,20 +995,24 @@ class IsolateViews():
996995
'''
997996

998997
def __enter__(self):
999-
1000-
self.sel = mc.ls(sl=True)
1001-
self.modelPanels = mc.getPanel(type='modelPanel')
1002-
1003-
#unfortunately there's no good way to know what's been isolated, so in this case if a view is isolated, skip it.
1004-
self.skip = list()
1005-
for each in self.modelPanels:
1006-
if mc.isolateSelect(each, query=True, state=True):
1007-
self.skip.append(each)
1008-
1009-
self.isolate(True)
1010-
1011-
mc.select(clear=True)
1012-
998+
999+
if MAYA_VERSION >= 2016.5:
1000+
if not mc.ogs(query=True, pause=True):
1001+
mc.ogs(pause=True)
1002+
else:
1003+
self.sel = mc.ls(sl=True)
1004+
self.modelPanels = mc.getPanel(type='modelPanel')
1005+
1006+
#unfortunately there's no good way to know what's been isolated, so in this case if a view is isolated, skip it.
1007+
self.skip = list()
1008+
for each in self.modelPanels:
1009+
if mc.isolateSelect(each, query=True, state=True):
1010+
self.skip.append(each)
1011+
1012+
self.isolate(True)
1013+
1014+
mc.select(clear=True)
1015+
10131016
self.resetAutoKey = mc.autoKeyframe(query=True, state=True)
10141017
mc.autoKeyframe(state=False)
10151018

@@ -1019,11 +1022,15 @@ def __exit__(self, *args):
10191022
#reset settings
10201023
mc.autoKeyframe(state=self.resetAutoKey)
10211024

1022-
if self.sel:
1023-
mc.select(self.sel)
1024-
1025-
self.isolate(False)
1026-
1025+
if MAYA_VERSION >= 2016.5:
1026+
if mc.ogs(query=True, pause=True):
1027+
mc.ogs(pause=True)
1028+
else:
1029+
if self.sel:
1030+
mc.select(self.sel)
1031+
1032+
self.isolate(False)
1033+
10271034

10281035
def isolate(self, state):
10291036

@@ -1860,7 +1867,7 @@ def about(self, *args):
18601867
mc.confirmDialog(title=self.name, message=text, button='Close')
18611868

18621869

1863-
def buttonWithPopup(self, label=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs=dict()):
1870+
def buttonWithPopup(self, label=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs={}):
18641871
'''
18651872
Create a button and attach a popup menu to a control with options to create a shelf button or a hotkey.
18661873
The argCommand should return a kwargs dictionary that can be used as args for the main command.
@@ -1967,7 +1974,7 @@ def _populateSelectionList(self, channel, control, *args):
19671974

19681975
class ButtonWithPopup():
19691976

1970-
def __init__(self, label=None, name=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs=dict(), **kwargs):
1977+
def __init__(self, label=None, name=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs={}, **kwargs):
19711978
'''
19721979
The fancy part of this object is the readUI_toArgs argument.
19731980
'''
@@ -2117,7 +2124,7 @@ def __init__(self, force=False):
21172124

21182125
def __enter__(self):
21192126
'''open the undo chunk'''
2120-
if self.force or mm.eval('getApplicationVersionAsFloat') < 2011:
2127+
if self.force or MAYA_VERSION < 2011:
21212128
self.force = True
21222129
mc.undoInfo(openChunk=True)
21232130

@@ -2296,3 +2303,5 @@ def cross(self, other):
22962303
# Revision 28: 2017-03-20 : bug fix and support for ml_puppet
22972304
#
22982305
# Revision 29: 2017-04-25 : matchBake support input frames
2306+
#
2307+
# Revision 30: 2017-06-13 : unify version test, isolate view update

0 commit comments

Comments
 (0)