81
81
82
82
try :
83
83
import ml_utilities as utl
84
- utl .upToDateCheck (32 )
84
+ utl .upToDateCheck (35 )
85
85
except ImportError :
86
86
result = mc .confirmDialog ( title = 'Module Not Found' ,
87
87
message = 'This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.' ,
111
111
112
112
113
113
PUP_ID_PREFIX = 'pupID_'
114
+ CONTROL_ATTR = PUP_ID_PREFIX + 'control'
114
115
115
116
def main ():
116
117
initPuppetContextMenu ()
@@ -145,6 +146,61 @@ def fkIkSwitchUI(*args):
145
146
annotation = 'Bake selected element from FK to IK and vice versa.' )
146
147
147
148
149
+ class SpaceSwitchUI (object ):
150
+
151
+ win_name = 'spaceSwitchWin'
152
+
153
+ def __init__ (self , title = 'SpaceSwitch' , width = 400 , height = 200 ):
154
+
155
+
156
+ sel = mc .ls (sl = True )
157
+ if not sel :
158
+ return
159
+
160
+ spaces = None
161
+ nodes = []
162
+ for each in sel :
163
+ data = getSpaceSwitchData (each )
164
+ if not data :
165
+ continue
166
+ nodes .append (each )
167
+ theseSpaces = set (data ['space' ]['enumValues' ])
168
+ if not spaces :
169
+ spaces = theseSpaces
170
+ else :
171
+ spaces .intersection (theseSpaces )
172
+
173
+ if not spaces :
174
+ return
175
+
176
+ self .width = width
177
+ self .height = height
178
+
179
+ self .close ()
180
+
181
+ mc .window (self .win_name , title = title , iconName = title , width = self .width , height = self .height , menuBar = True )
182
+ self .column = mc .columnLayout (adj = True )
183
+
184
+ for space in list (spaces ):
185
+ mc .button (space , command = partial (self .setSpace , nodes , space ))
186
+
187
+ self .show ()
188
+
189
+
190
+ def setSpace (self , nodes , space , * args ):
191
+ switchSpace (nodes = nodes , toSpace = space , switchRange = True , bakeOnOnes = False )
192
+ self .close ()
193
+
194
+ def close (self ):
195
+ if mc .window (self .win_name , exists = True ):
196
+ mc .deleteUI (self .win_name )
197
+
198
+ def show (self ):
199
+ mc .showWindow (self .win_name )
200
+ mc .window (self .win_name , edit = True , width = self .width , height = self .height )
201
+
202
+
203
+
148
204
def fkIkSwitchSel (* args ):
149
205
fkIkSwitch ()
150
206
@@ -154,7 +210,8 @@ def fkIkSwitchRangeSel(*args):
154
210
155
211
156
212
def getPuppets (node = None ):
157
-
213
+
214
+ #LEGACY:
158
215
if node :
159
216
puppets = []
160
217
if not isinstance (node , (list ,tuple )):
@@ -322,6 +379,8 @@ def getTag(node, tag):
322
379
323
380
324
381
def getNodeType (node ):
382
+ if mc .attributeQuery ('asset_type' , node = node , exists = True ):
383
+ return mc .getAttr (node + '.asset_type' , asString = True )
325
384
return getTag (node , 'nodeType' )
326
385
327
386
@@ -338,7 +397,6 @@ def getNodesOfType(nodeType, namespaceFromNodes=None):
338
397
namespaces .append (utl .getNamespace (each ))
339
398
else :
340
399
namespaces = ['*:' ,'' ]
341
-
342
400
for ns in list (set (namespaces )):
343
401
if nodeType == 'control' or nodeType == 'element' or nodeType == 'puppet' :
344
402
#special case for commonly queried nodes, for speed
@@ -715,7 +773,19 @@ def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
715
773
716
774
if switchRange :
717
775
start , end = utl .frameRange ()
718
-
776
+
777
+ #check for dynamics
778
+ for node in nodes :
779
+ nucleus = utl .getNucleusHistory (node )
780
+ if not nucleus :
781
+ parent = mc .listRelatives (node , parent = True , pa = True )
782
+ if parent :
783
+ nucleus = utl .getNucleusHistory (parent [0 ])
784
+ if nucleus :
785
+ if mc .getAttr (nucleus + '.enable' ):
786
+ start = mc .getAttr (nucleus + '.startFrame' )
787
+ bakeOnOnes = True
788
+ break
719
789
#need to support this eventually for controls which have multiple space attributes.
720
790
selChan = utl .getSelectedChannels ()
721
791
@@ -733,7 +803,8 @@ def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
733
803
else :
734
804
#silly, but take the shortest one, as that's usually default
735
805
ssAttr = min (ssData .keys (), key = len )
736
-
806
+
807
+ value = None
737
808
if isinstance (toSpace , basestring ):
738
809
for i , e in enumerate (ssData [ssAttr ]['enumValues' ]):
739
810
if e .lower () == toSpace .lower ():
@@ -774,7 +845,7 @@ def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
774
845
return
775
846
776
847
if switchRange :
777
- utl .matchBake (controls , locators , maintainOffset = True )
848
+ utl .matchBake (controls , locators , maintainOffset = True , bakeOnOnes = bakeOnOnes )
778
849
779
850
for ctrl , attr , value in zip (controls , attributes , values ):
780
851
if mc .keyframe (ctrl + '.' + attr , query = True , name = True ):
@@ -901,8 +972,7 @@ def initPuppetContextMenu():
901
972
902
973
903
974
def isNodePuppetControl (node ):
904
-
905
- if mc .attributeQuery (PUP_ID_PREFIX + 'nodeType' , exists = True , node = node ):
975
+ if mc .attributeQuery (PUP_ID_PREFIX + 'control' , exists = True , node = node ):
906
976
return True
907
977
if getNodeType (node ) == 'control' :
908
978
return True
@@ -918,11 +988,11 @@ def getSpaceSwitchData(node):
918
988
if not attrs :
919
989
return data
920
990
921
- ssAttrs = [x for x in attrs if 'paceSwitch' in x ]
991
+ ssAttrs = [x for x in attrs if 'paceSwitch' in x or x == 'space' ]
922
992
for attr in ssAttrs :
923
993
enumValues = []
924
994
spaceEnum = 'space'
925
- if attr == 'spaceSwitch' :
995
+ if attr == 'spaceSwitch' or attr == 'space' :
926
996
if not 'space' in attrs :
927
997
spaceEnum = 'spaceSwitch'
928
998
enumValues = mc .attributeQuery (spaceEnum , node = node , listEnum = True )
@@ -1139,6 +1209,14 @@ def convertRotateOrderUI(nodes, *args):
1139
1209
# __________________________________
1140
1210
# == POSE AND ANIM MIRRORING =======
1141
1211
1212
+ def getMirrorName (node , a = 'Lf_' , b = 'Rt_' ):
1213
+ if a in node :
1214
+ return node .replace (a ,b )
1215
+ elif b in node :
1216
+ return node .replace (b ,a )
1217
+
1218
+
1219
+
1142
1220
def getMirrorMap (nodes = None ):
1143
1221
'''
1144
1222
Returns a map of all paired nodes within a puppet
@@ -1172,11 +1250,16 @@ def getMirrorPairs(nodes):
1172
1250
'''
1173
1251
1174
1252
nodes = mc .ls (nodes , long = True )
1175
- mirrorMap = getMirrorMap (nodes )
1253
+ # mirrorMap = getMirrorMap(nodes)
1176
1254
mirrorPairs = {}
1255
+ #for each in nodes:
1256
+ #if each in mirrorMap:
1257
+ #mirrorPairs[each] = mirrorMap[each]
1177
1258
for each in nodes :
1178
- if each in mirrorMap :
1179
- mirrorPairs [each ] = mirrorMap [each ]
1259
+ mirror = getMirrorName (each )
1260
+ if mc .objExists (mirror ):
1261
+ mirrorPairs [each ] = mirror
1262
+
1180
1263
return mirrorPairs
1181
1264
1182
1265
@@ -1239,7 +1322,13 @@ def copyPose(fromNode, toNode, flip=False):
1239
1322
except :pass
1240
1323
1241
1324
1242
- def mirrorPose (nodes , * args ):
1325
+ def mirrorPose (nodes = None , * args ):
1326
+
1327
+ if not nodes :
1328
+ nodes = mc .ls (sl = True )
1329
+
1330
+ if not nodes :
1331
+ raise RuntimeError ('No nodes provided to mirror.' )
1243
1332
1244
1333
pairs = getMirrorPairs (nodes )
1245
1334
done = []
@@ -1249,7 +1338,13 @@ def mirrorPose(nodes, *args):
1249
1338
done .append (mirror )
1250
1339
1251
1340
1252
- def flipPose (nodes , * args ):
1341
+ def flipPose (nodes = None , * args ):
1342
+
1343
+ if not nodes :
1344
+ nodes = mc .ls (sl = True )
1345
+
1346
+ if not nodes :
1347
+ raise RuntimeError ('No nodes provided to mirror.' )
1253
1348
1254
1349
nodes = mc .ls (nodes , long = True )
1255
1350
@@ -1273,7 +1368,7 @@ def flipPose(nodes, *args):
1273
1368
1274
1369
1275
1370
def copyAnimation (fromNode , toNode ):
1276
-
1371
+ print 'copy' , fromNode . split ( '|' )[ - 1 ], toNode . split ( '|' )[ - 1 ]
1277
1372
mc .copyKey (fromNode )
1278
1373
mc .pasteKey (toNode , option = 'replaceCompletely' )
1279
1374
for axis in getMirrorAxis (toNode ):
@@ -1326,8 +1421,14 @@ def swapAnimation(fromNode, toNode):
1326
1421
mc .scaleKey (fromNode , attribute = axis , valueScale = - 1 )
1327
1422
1328
1423
1329
- def mirrorAnimation (nodes , * args ):
1330
-
1424
+ def mirrorAnimation (nodes = None , * args ):
1425
+
1426
+ if not nodes :
1427
+ nodes = mc .ls (sl = True )
1428
+
1429
+ if not nodes :
1430
+ raise RuntimeError ('No nodes provided to mirror.' )
1431
+
1331
1432
pairs = getMirrorPairs (nodes )
1332
1433
done = []
1333
1434
for node , mirror in pairs .items ():
0 commit comments