Suffix if statement
Posted
by
Aardschok
on Stack Overflow
See other posts from Stack Overflow
or by Aardschok
Published on 2014-06-08T21:21:28Z
Indexed on
2014/06/08
21:24 UTC
Read the original article
Hit count: 206
I was looking for a way to add a suffix to jointchain in Maya. The jointchain has specific naming so I create a list with the names they need to be. The first chain has "_1" as suffix, result:
R_Clavicle_1|R_UpperArm_1|R_UnderArm_1|R_Wrist_1
When I create the second this is the result:
R_Clavicle_2|R_UpperArm_1|R_UnderArm_1|R_Wrist_1
The code:
DRClavPos = cmds.xform ('DRClavicle', q=True, ws=True, t=True)
DRUpArmPos = cmds.xform ('DRUpperArm', q=True, ws=True, t=True)
DRUnArmPos = cmds.xform ('DRUnderArm', q=True, ws=True, t=True)
DRWristPos = cmds.xform ('DRWrist', q=True, ws=True, t=True), cmds.xform('DRWrist', q=True, os=True, ro=True)
suffix = 1
jntsA = cmds.ls(type="joint", long=True)
while True:
jntname = ["R_Clavicle_"+str(suffix),"R_UpperArm_"+str(suffix),"R_UnderArm_"+str(suffix),"R_Wrist_"+str(suffix)]
if jntname not in jntsA:
cmds.select (d=True)
cmds.joint ( p=(DRClavPos))
cmds.joint ( p=(DRUpArmPos))
cmds.joint ( 'joint1', e=True, zso=True, oj='xyz', radius=0.5, n=jntname[0])
cmds.joint ( p=(DRUnArmPos))
cmds.joint ( 'joint2', e=True, zso=True, oj='xyz', radius=0.5, n=jntname[1])
cmds.joint ( p=(DRWristPos[0]))
cmds.joint ( 'joint3', e=True, zso=True, oj='xyz', radius=0.5, n=jntname[2])
cmds.rename ('joint4', jntname[3])
cmds.select ( cl=True)
break
else:
suffix + 1
I tried adding +1 in jntname which resulted in a good second chain but the third chain had "_2" after R_Clavicle_3
The code, in my eyes should work. Can anybody point me in the correct direction :)
© Stack Overflow or respective owner