コードのおさらい
from maya import cmds
# joint階層の名前を変更する
joints = cmds.ls(selection=True)
for joint in joints:
cmds.rename(joint, "{}_baseJoint".format(joint))
# ユニークな名前で複製する
cmds.duplicate(rc=True)
# 複製したジョイント階層の名前を変更する
joints = cmds.ls(selection=True)
for joint in joints:
target_joint = joint.replace("baseJoint1", "targetJoint")
cmds.rename(joint, target_joint)
# baseJointのshapeにcircleを作る
joints = cmds.ls(selection=True)
for joint in joints:
circle = cmds.circle(normal=[1,0,0], constructionHistory=False)[0]
circle_shape = cmds.listRelatives(circle, shapes=True)[0]
cmds.parent(circle_shape, joint, relative=True, shape=True)
cmds.delete(circle)
cmds.rename(circle_shape, "{}Shape".format(joint))
# joint.drawStyle=Noneにする
joints = cmds.ls(selection=True, dagObjects=True, type="joint")
for joint in joints:
cmds.setAttr("{}.drawStyle".format(joint), 2)
# baseJoint階層でtargetJoint階層を動かす。
joints = cmds.ls(selection=True, dagObjects=True, type="joint")
for joint in joints:
target_joint = joint.replace("baseJoint", "targetJoint")
for i in "XYZ":
cmds.connectAttr(
"{}.translate{}".format(joint, i),
"{}.translate{}".format(target_joint, i)
)
cmds.connectAttr(
"{}.rotate{}".format(joint, i),
"{}.rotate{}".format(target_joint, i)
)
cmds.connectAttr(
"{}.scale{}".format(joint, i),
"{}.scale{}".format(target_joint, i)
)
Pythonのおすすめ書籍
コメント