/
armRig.py
572 lines (395 loc) · 22.3 KB
/
armRig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# ====================================================================================== #
# ====================================================================================== #
import pymel.core as pm
import maya.cmds as cmds
import imp
import sys
path = r'D:\00.Documents\03. Scripting and Programming\Maya Scripts'
if path not in sys.path:
sys.path.append(path)
import createControllers
import createJoints
# ====================================================================================== #
# ====================================================================================== #
# ================= Function to connect IKFK switch =================================== #
def ConnectIKFKSwitch(prefix, Switch_CTRL, CTRLs_GRP, elbowIK, constrGRP):
switchAttr = pm.listAttr(Switch_CTRL, s = True, k = True, v = True)
lenAttr = len(switchAttr)
IKFKSwitchAttr = switchAttr[lenAttr - 1]
# create reverse utility node
revUtility = pm.shadingNode('reverse', n= str(prefix) + 'arm_IK_FK_reverse_node', asUtility=True)
pm.connectAttr(str(Switch_CTRL) + '.' + str(IKFKSwitchAttr), str(revUtility) + '.inputX', force = True)
#ConnectIKFKConstr(utilNode, Constr, prefix, jnt, Switch_CTRL):
createJoints.ConnectIKFKConstr(revUtility, constrGRP[0], prefix, 'shoulder', Switch_CTRL)
createJoints.ConnectIKFKConstr(revUtility, constrGRP[1], prefix, 'elbow', Switch_CTRL)
createJoints.ConnectIKFKConstr(revUtility, constrGRP[2], prefix, 'wrist', Switch_CTRL)
ArmInd = CTRLs_GRP.index( str(prefix) + 'arm_IK_CTRL_offset_GRP')
arm_CTRL = pm.listRelatives(CTRLs_GRP[ArmInd])[0]
PoleInd = CTRLs_GRP.index( str(prefix) + 'pole_vector_offset_GRP')
ShoulderInd = CTRLs_GRP.index( str(prefix) + 'shoulder_FK_CTRL_offset_GRP')
# constrain
pm.orientConstraint(arm_CTRL, elbowIK, mo = False)
pm.connectAttr(str(Switch_CTRL) + '.' + str(IKFKSwitchAttr), str(CTRLs_GRP[ArmInd]) + '.visibility', force = True)
pm.connectAttr(str(Switch_CTRL) + '.' + str(IKFKSwitchAttr), str(CTRLs_GRP[PoleInd]) + '.visibility', force = True)
pm.connectAttr(str(revUtility) + '.outputX', str(CTRLs_GRP[ShoulderInd]) + '.visibility', force = True)
# ================= Function to create FK CTRLS ======================================= #
def CreateFK(prefix, jntFKList,ctrl_GRP):
offset_GRP_Name = '_offset_GRP'
# shoulder CTRL
shoulder_CTR_Name = str(prefix) + 'shoulder_FK_CTRL'
createControllers.CreateCircleCTRL(str(shoulder_CTR_Name), ctrl_GRP, jntFKList[0], (0,1,0), 0.6, (0,0,-100))
# elbow CTRL
elbow_CTR_Name = str(prefix) + 'elbow_FK_CTRL'
createControllers.CreateCircleCTRL(str(elbow_CTR_Name), ctrl_GRP, jntFKList[1], (0,1,0), 0.5, (0,0,-100))
# wrist CTRL
wrist_CTR_Name = str(prefix) + 'wrist_FK_CTRL'
createControllers.CreateCircleCTRL(str(wrist_CTR_Name), ctrl_GRP, jntFKList[2], (0,1,0), 0.3, (0,0,-100))
# parent GTRLS
pm.parent(str(wrist_CTR_Name) + str(offset_GRP_Name), elbow_CTR_Name)
pm.parent(str(elbow_CTR_Name) + str(offset_GRP_Name), shoulder_CTR_Name)
# add CTRL to list
ctrl_GRP.extend([str(shoulder_CTR_Name) + str(offset_GRP_Name) ,str(wrist_CTR_Name) + str(offset_GRP_Name), str(elbow_CTR_Name) + str(offset_GRP_Name)])
# ================= Function to create IK CTRLS ======================================= #
def CreateIK(prefix, jntIKList, ctrl_GRP):
offset_GRP_Name = '_offset_GRP'
# create arm CTRL ========================
Arm_CTRL = str(prefix) + "arm_IK_CTRL"
Arm_Offset_GRP = str(Arm_CTRL) + str(offset_GRP_Name)
createControllers.CreateStarCTRL(Arm_CTRL, ctrl_GRP, 0.6, [0.4, 0.4, 0.4], (1,0,0))
# move offset GRP to wrist jnt, remove const
tempConst = pm.parentConstraint(jntIKList[2], str(Arm_Offset_GRP))
pm.delete(tempConst)
# create IK handle
arm_ik = pm.ikHandle( n = str(prefix) + 'IK_Handle', sj=jntIKList[0], ee=jntIKList[2])
pm.parent(arm_ik[0], Arm_CTRL)
# create pole vector CTRL ================
poleVector_CTRL = str(prefix) + 'pole_vector'
pole_GRP = str(poleVector_CTRL) + str(offset_GRP_Name)
createControllers.CreateBallCTRL(str(poleVector_CTRL), ctrl_GRP, 0.15)
# move offset GRP to wrist jnt, remove const
tempConst = pm.parentConstraint(jntIKList[1], str(pole_GRP), sr = ['x', 'y', 'z'])
pm.delete(tempConst)
createControllers.CleanHist(pole_GRP)
# point + aim constraint CTRL to prevent joint from moving after pole V Constr
pointConst = pm.pointConstraint( str(jntIKList[0]), str(jntIKList[2]), str(poleVector_CTRL), mo= False, w=1 )
pm.delete(pointConst)
aimConst = pm.aimConstraint( str(jntIKList[1]), str(poleVector_CTRL), mo= False, w=1 )
pm.delete(aimConst)
# constrain PV
PVConstr = pm.poleVectorConstraint(poleVector_CTRL, arm_ik[0], n = str(poleVector_CTRL) + '_constraint')
pm.move(str(poleVector_CTRL), (1,0, 0 ), os = True, wd = False, relative = True)
# clean hist, parent and add CTRS to list
createControllers.CleanHist(poleVector_CTRL)
pm.parent(poleVector_CTRL, pole_GRP)
ctrl_GRP.extend([str(Arm_Offset_GRP), pole_GRP])
# ================= Function to create IKFK Chain ====================================== #
def IK_FKChain(prefix, jnList, IKJntList, FKJntList, ctrl_GRP):
# create IK jnt chain =============
IKChain = cmds.duplicate(str(jnList[1]), n= str(jnList[1] + '_IK'))[0]
pm.parent(IKChain, world=True )
createControllers.RecolourObj(IKChain, 'joint')
# rename jnts
dagObjIK = pm.listRelatives(IKChain, ad=True, type="joint")
for y in dagObjIK:
pm.rename(y, str(y) + '_IK')
IKJntList.append(y)
createControllers.RecolourObj(y, 'joint')
# append jnt & rev list
IKJntList.append(IKChain)
IKJntList = IKJntList[::-1]
CreateIK(prefix, IKJntList,ctrl_GRP)
# create FK jnt chain =============
FKChain = cmds.duplicate(str(jnList[1]), n= str(jnList[1] + '_FK'))[0]
pm.parent(FKChain, world=True )
createControllers.RecolourObj(FKChain, 'joint')
# rename jnts
dagObjFK = pm.listRelatives(FKChain, ad=True, type="joint")
for x in dagObjFK:
pm.rename(x, str(x) + '_FK')
FKJntList.append(x)
createControllers.RecolourObj(x, 'joint')
# append jnt & rev list
FKJntList.append(FKChain)
FKJntList = FKJntList[::-1]
CreateFK(prefix, FKJntList,ctrl_GRP)
# ================= Function to create Arm ============================================ #
#def CreateArm(WS_LOC, spaceGrps, rigging_GRP, ctrl_GRP, skeleton_GRP, vis_aid_GRP, jntList, IKJntList, FKJntList, CTRLs, prefix, jntRadius):
def CreateArm(rigging_GRPs, CTRLs_GRP, prefix, jntList, IKJntList, FKJntList, jntRadius):
imp.reload(createControllers)
imp.reload(createJoints)
# ================================================================== *
offset_GRP_Name = '_offset_GRP'
axis = 1
if prefix == 'R_':
axis = -1
# ===================== create simple arm jnts ===================== *
clavicle = pm.joint(n = str(prefix) + 'clavicle_jnt', p = (axis * 0.4,0,0), rad = jntRadius)
shoulder = pm.joint(n = str(prefix) + 'shoulder_jnt', p = (axis * 1.3,0.3,0.4), rad = jntRadius)
elbow = pm.joint(n = str(prefix) + 'elbow_jnt', p = (axis * 3,0,0), rad = jntRadius)
dist = createControllers.Distance(shoulder,elbow)
wrist = pm.joint(n = str(prefix) + 'wrist_jnt', p = ( axis *(3 + dist),-0.1,0.4), rad = jntRadius)
pm.parent(clavicle, world=True)
# set jnt orientation
pm.joint(clavicle, e=True, zso = True, oj='xyz', sao = 'yup')
pm.joint(shoulder, e=True, zso = True, oj='xyz', sao = 'yup')
pm.joint(elbow, e=True, zso = True, oj='xyz', sao = 'yup')
pm.joint(wrist, e=True, zso = True, oj='none')
# add jnts to list & create IK FK jnts
jntList.extend([clavicle, shoulder, elbow, wrist])
#clavicle CTRL
clavicle_Ctrl = str(prefix) + 'clavicle_CTRL'
createControllers.CreateCircleCTRL(str(clavicle_Ctrl),CTRLs_GRP, clavicle, (0,1,0), 0.8, (0,0,80))
# ===================== create IK FK chain ========================= *
IK_FKChain(prefix, jntList, IKJntList, FKJntList, CTRLs_GRP)
IKJntList = IKJntList[::-1]
FKJntList = FKJntList[::-1]
# constrain jnts to IK/FK
constrGRP = []
shoulderConstr = pm.parentConstraint(FKJntList[0], IKJntList[0], str(shoulder), mo = False, w=1)
elbowConstr = pm.parentConstraint(FKJntList[1], IKJntList[1], str(elbow), mo = False, w=1)
wristConstr = pm.parentConstraint(FKJntList[2], IKJntList[2], str(wrist), mo = False, w=1)
constrGRP.extend([shoulderConstr, elbowConstr, wristConstr])
# ===================== create Hand ================================ *
handJntList = createJoints.CreateHand(prefix, axis, wrist, jntRadius)
jntList.extend(handJntList)
# ===================== create Twist Jnts ========================== *
#twistJntList = createJoints.CreateArmTwistJnts(prefix, jntList, jntRadius)
# ===================== create IKFK Switch ========================== *
Switch_CTRL = str(prefix) + 'IK_FK_Switch_CTRL'
Switch_CTRL_Line = str(prefix) + 'IK_FK_VIS'
clusterGRP = createControllers.CreateIKFKSwitch(axis, Switch_CTRL, CTRLs_GRP, Switch_CTRL_Line, wrist)
ConnectIKFKSwitch(prefix, Switch_CTRL, CTRLs_GRP, IKJntList[2], constrGRP)
# ===================== Tidy ======================================= *
# group vis & clusters
pm.parent(Switch_CTRL_Line, rigging_GRPs[3])
pm.parent(str(clusterGRP[1][1]), str(Switch_CTRL) + str(offset_GRP_Name))
pm.parent(str(clusterGRP[0][1]), str(rigging_GRPs[1]))
# group ctrls
pm.parent(str(CTRLs_GRP[0]), str(rigging_GRPs[1]))
pm.parent(str(CTRLs_GRP[1]), str(rigging_GRPs[1]))
pm.parent(str(CTRLs_GRP[2]), str(rigging_GRPs[1]))
pm.parent(str(CTRLs_GRP[5]), str(clavicle_Ctrl))
# group IK/FK jnts
IK_GRP = pm.group( em=True, name= str(prefix) + 'IK_GRP' )
pm.parent(str(IKJntList[0]) , IK_GRP)
FK_GRP = pm.group( em=True, name= str(prefix) + 'FK_GRP' )
pm.parent(str(FKJntList[0]) , FK_GRP)
arm_GRP = pm.group( em=True, name= str(prefix) + 'arm_GRP' )
pm.parent(FK_GRP, arm_GRP)
pm.parent(IK_GRP, arm_GRP)
pm.parent(arm_GRP, rigging_GRPs[0])
pm.parent(jntList[0], rigging_GRPs[2])
pm.parent(str(CTRLs_GRP[11]), str(rigging_GRPs[4]))
# constrain arm grp to clavicle
pm.parentConstraint(clavicle_Ctrl,arm_GRP, mo = True, w = 1)
# ================= Function to create PRNT Switch ==================================== #
def CreateSpaceSwitch(space_Grps, World_LOC, LOC_Const, m_CTRL, switch_spaces, CTRL_List):
# variables ================================================================
CTRL_enums = []
new_Space_GRPS = []
new_Space_CTRLs = []
inbetween_CTRL_GRPs = []
switch_Constraints_List = []
# Create stuff for main CTRL ===============================================
# find offset grp for CTRL
main_CTRL_offs_GRP_Ind = CTRL_List.index(str(m_CTRL) + '_offset_GRP')
main_offset_CTRL_GRP = CTRL_List[main_CTRL_offs_GRP_Ind]
# get SPACE group for main space
main_GRP_Space = ''
m_index = -1
if str(m_CTRL) + '_Space' in space_Grps:
m_index = space_Grps.index(str(m_CTRL) + '_Space')
main_GRP_Space = space_Grps[m_index]
# if group does not exist
if m_index == -1:
m_ctrl_name = str(m_CTRL) + '_Space'
main_GRP_Space = pm.group( em=True, name= str(m_ctrl_name))
pm.parent(main_GRP_Space, space_Grps[0])
space_Grps.append(str(m_ctrl_name))
# constrain to main CTRL
m_space_Const = pm.parentConstraint(main_offset_CTRL_GRP, main_GRP_Space, n= str(m_CTRL) + '_space_Parent_Const', mo = False, w = 1)
switch_Constraints_List.append(m_space_Const)
# Create main CTRL offset GRP
main_CTRL_Offset = pm.group( em=True, name= str(m_CTRL) + '_Offset')
pm.parent(main_CTRL_Offset, main_offset_CTRL_GRP)
# move grp to ctrl pos & parent ctrl to it
tempConst = pm.parentConstraint(main_offset_CTRL_GRP, main_CTRL_Offset, mo = False, w = 1)
pm.delete(tempConst)
pm.parent(m_CTRL, main_CTRL_Offset)
# add main CTRL to enum
ep = '_'
if m_CTRL[1] is '_':
splitString = m_CTRL.split(ep, 2)
enum = splitString[0] + '_' + splitString[1]
CTRL_enums.append(enum)
else:
splitString = m_CTRL.split(ep, 2)
enum = splitString[0]
CTRL_enums.append(enum)
print CTRL_enums
# WORLD ctrl ==================================================
world_Ind = -1
if 'world_LOC' in switch_spaces:
world_Ind = switch_spaces.index('world_LOC')
# if there is a world space
if world_Ind >= 0:
world_Space = switch_spaces[world_Ind]
switch_spaces.remove(world_Space)
CTRL_enums.append('World')
new_Space_GRPS.append(world_Space)
# create current space GRP in world space GRP ======
world_mCTRL_Space = pm.group( em=True, name= 'world_LOC_' + str(m_CTRL) + '_Space')
# move GRP
tempConst = pm.parentConstraint(main_GRP_Space, world_mCTRL_Space, mo = False, w = 1)
pm.delete(tempConst)
pm.parent(world_mCTRL_Space,space_Grps[1])
new_Space_GRPS.append(world_mCTRL_Space)
# create inbetween grp
world_Space_inbetween = pm.group( em=True, name= 'world_LOC_' + str(m_CTRL) + '_Space_inbetween')
pm.parent(world_Space_inbetween, main_offset_CTRL_GRP)
tempConst = pm.parentConstraint(main_offset_CTRL_GRP, world_Space_inbetween, mo = False, w = 1)
pm.delete(tempConst)
inbetween_CTRL_GRPs.append(world_Space_inbetween)
# constrain inbetween GRP to world
worldConst = pm.parentConstraint(world_mCTRL_Space, world_Space_inbetween, name = 'WORLD_' + str(m_CTRL) + '_inbetween_prnt_Constr',mo = False, w = 1)
switch_Constraints_List.append(worldConst)
# SPACES ctrl ==================================================
for space in switch_spaces:
# check if space GRP already exists
GRP_Space = ''
space_GRP_ind = -1
if space + '_Space' in space_Grps:
space_GRP_ind = space_Grps.index(space + '_Space')
GRP_Space = space_Grps[space_GRP_ind]
# if GRP doesn't exist
if space_GRP_ind == -1:
GRP_Space = pm.group( em = True, n = str(space) + '_Space')
space_Grps.append(str(GRP_Space))
# move GRP
tempConst = pm.parentConstraint(space, GRP_Space, mo = False, w = 1)
pm.delete(tempConst)
pm.parent(GRP_Space, space_Grps[0])
# constrain to main CTRL
space_Const = pm.parentConstraint(space, GRP_Space, n= str(space) + '_space_Parent_Const', mo = False, w = 1)
switch_Constraints_List.append(space_Const)
new_Space_GRPS.append(GRP_Space)
enum = ''
if space[1] == '_':
splitString = space.split(ep, 3)
enum = splitString[0] + '_' + splitString[1]
CTRL_enums.append(enum)
else:
splitString = space.split(ep, 2)
enum = splitString[0]
CTRL_enums.append(enum)
# create offset grp in space grp ======
space_mCTRL_Space = pm.group( em=True, name= str(enum) + '_' + str(m_CTRL) + '_Space')
pm.parent(space_mCTRL_Space, GRP_Space)
# move GRP
tempConst = pm.parentConstraint(main_GRP_Space, space_mCTRL_Space, mo = False, w = 1)
pm.delete(tempConst)
new_Space_GRPS.append(space_mCTRL_Space)
# create inbetween grp ============
space_inbetween = pm.group( em=True, name= str(space) + '_' + str(m_CTRL) + '_Space_inbetween')
pm.parent(space_inbetween, main_offset_CTRL_GRP)
# move grp
tempConst = pm.parentConstraint(main_offset_CTRL_GRP, space_inbetween, mo = False, w = 1)
pm.delete(tempConst)
inbetween_CTRL_GRPs.append(space_inbetween)
# constrain
spaceConst = pm.parentConstraint(space_mCTRL_Space, space_inbetween, n = str(space) + '_' + str(m_CTRL) + '_inbetween_prnt_Constr', mo = False, w = 1)
switch_Constraints_List.append(spaceConst)
# Create Parent switch ==========
# create RESULT constrain
resultConst = pm.parentConstraint(inbetween_CTRL_GRPs, main_CTRL_Offset, mo = False, w = 1, n= str(m_CTRL) + '_RESULT_constraint')
# get CTRL & add switch attr
ctrl = main_CTRL_Offset.listRelatives(type = 'transform')
NURB_ctrl = ctrl[0]
#add switch space Attr to CTRL
switch_Space_Attr = pm.addAttr(NURB_ctrl, longName='Parent_Switch', at = 'enum', en = CTRL_enums, k=True)
pm.setAttr(NURB_ctrl + '.Parent_Switch', 1)
# Get weight attr for nodes ===
attributes = resultConst.listAttr(s = True)
weight_Attr = []
for att in attributes:
splitAttr = att.split('.', 2)
if '_inbetweenW' in splitAttr[1]:
weight_Attr.append(att)
# WORLD CONDITION NODE ==============================
world_Const = "WORLD_" + str(m_CTRL) + "_inbetween_prnt_Constr"
world_Ind = -1
if world_Const in switch_Constraints_List:
world_Ind = switch_Constraints_List.index(world_Const)
if world_Ind >= 0:
# create condition node
condition_World = pm.shadingNode('condition', n= str(NURB_ctrl) + '_condition_node_WORLD', asUtility=True)
# connect switch attr to condition node
pm.connectAttr(str(NURB_ctrl) + '.Parent_Switch', str(condition_World) + '.firstTerm', force = True)
w_enum_ind = CTRL_enums.index('World')
# set connection attr
pm.setAttr(str(condition_World) + '.secondTerm', w_enum_ind)
pm.setAttr(str(condition_World) + '.colorIfTrueR', 1)
pm.setAttr(str(condition_World) + '.colorIfTrueG', 0)
pm.setAttr(str(condition_World) + '.colorIfTrueB', 0)
pm.setAttr(str(condition_World) + '.colorIfFalseR', 0)
pm.setAttr(str(condition_World) + '.colorIfFalseG', 10)
pm.setAttr(str(condition_World) + '.colorIfFalseB', 0)
# connect condition node attr to inbetween constrain
pm.connectAttr(str(condition_World) + '.outColorR' , str(switch_Constraints_List[world_Ind] + '.visibility'), force = True)
pm.connectAttr(str(condition_World) + '.outColorG' , str(switch_Constraints_List[world_Ind] + '.nodeState'), force = True)
# find world weight Attr on result constr
world_Attr_Ind = -1
for wAtt in weight_Attr:
if "world" in str(wAtt):
world_Attr_Ind = weight_Attr.index(wAtt)
if world_Attr_Ind >= 0:
world_Inbetween_Weight_Attr = weight_Attr[world_Attr_Ind]
weight_Attr.remove(world_Inbetween_Weight_Attr)
# connect condition node attr to result constrain
pm.connectAttr(str(condition_World) + '.outColorR' , str(world_Inbetween_Weight_Attr), force = True)
# SPACE CONDITION NODE =========
for space in switch_spaces:
# get space prefix
prefix_Space = ''
enum_ind = -1
if space[1] == '_':
splitString = space.split(ep, 2)
prefix_Space = splitString[0] + '_' + splitString[1]
enum_ind = CTRL_enums.index(prefix_Space)
prefix_Space = prefix_Space + '_' + splitString[2]
else:
splitString = space.split(ep, 2)
prefix_Space = splitString[0]
enum_ind = CTRL_enums.index(prefix_Space)
prefix_Space = prefix_Space + '_' + splitString[1]
# get index
space_Constr = prefix_Space + '_' + str(m_CTRL) + "_inbetween_prnt_Constr"
space_Ind = -1
if space_Constr in switch_Constraints_List:
space_Ind = switch_Constraints_List.index(space_Constr)
if space_Ind >= 0:
# create condition node
condition_Node = pm.shadingNode('condition', n= str(NURB_ctrl) + '_condition_node_' + str(space), asUtility=True)
# connect switch attr to condition node
pm.connectAttr(str(NURB_ctrl) + '.Parent_Switch', str(condition_Node) + '.firstTerm', force = True)
# set connection attr
pm.setAttr(str(condition_Node) + '.secondTerm', enum_ind)
pm.setAttr(str(condition_Node) + '.colorIfTrueR', 1)
pm.setAttr(str(condition_Node) + '.colorIfTrueG', 0)
pm.setAttr(str(condition_Node) + '.colorIfTrueB', 0)
pm.setAttr(str(condition_Node) + '.colorIfFalseR', 0)
pm.setAttr(str(condition_Node) + '.colorIfFalseG', 10)
pm.setAttr(str(condition_Node) + '.colorIfFalseB', 0)
# connect condition node attr to inbetween constrain
pm.connectAttr(str(condition_Node) + '.outColorR' , str(switch_Constraints_List[space_Ind]) + '.visibility', force = True)
pm.connectAttr(str(condition_Node) + '.outColorG' , str(switch_Constraints_List[space_Ind]) + '.nodeState', force = True)
# find space weight Attr on result constr
node_Attr_Ind = -1
for inAtt in weight_Attr:
if space in str(inAtt):
node_Attr_Ind = weight_Attr.index(inAtt)
if node_Attr_Ind >= 0:
# connect condition node attr to result constrain
pm.connectAttr(str(condition_Node) + '.outColorR' , str(weight_Attr[node_Attr_Ind]), force = True)
# ====================================================================================== #
# ====================================================================================== #