我正在寻找一种在 Maya 中为关节链添加后缀的方法。关节链具有特定的命名,因此我创建了一个包含它们需要的名称的列表。第一个链以“_1”为后缀,结果:
R_Clavicle_1|R_UpperArm_1|R_UnderArm_1|R_Wrist_1
当我创建第二个时,结果如下:
R_Clavicle_2|R_UpperArm_1|R_UnderArm_1|R_Wrist_1
编码:
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
我尝试在 jntname 中添加 +1,这导致第二条链很好,但第三条链在 R_Clavicle_3 之后有“_2”
在我看来,代码应该可以工作。谁能指出我正确的方向:)