def fkChain(ctrlType="circle", color="red", axis="x", *args):
"""
puts a correctly oriented control onto each joint of selected chain. Will name the controls after the joint names and parent them according to the joint order
Select the top joint of a chain and call fkChain(ARGS)
Arguments: ctrlType ("sphere", "circle", "cube", etc), color ("red", "darkRed",etc. See zbw_rig.createControl for full list), axis ("x", "y", "x")
"""
#get the selected joint's chain of joints
sel = cmds.ls(sl=True, type="joint")
#initialize lists
ctrlList = []
groupList = []
#for now just do one chain
if len(sel) != 1:
cmds.error("please select only the top level joint of one chain")
else:
#get the hierarchy of just joints
allChain = cmds.select(sel[0], hi=True)
chain = cmds.ls(sl=True, type="joint")
chainSize = len(chain)
for jnt in chain:
#get the rot order
rotOrder = cmds.getAttr("%s.rotateOrder"%jnt)
#control name
ctrlName = jnt + "_CTRL"
#create control
ctrl = createControl(ctrlName, ctrlType, axis, color)
#snap that control to the joint (group orient)
groupOrient(jnt, ctrl, "GRP")
group = ctrl + "_GRP"
#orient constrain the joint to the control
cmds.orientConstraint(ctrl, jnt)
#set rotation order for the control and group
cmds.setAttr("%s.rotateOrder"%ctrl, rotOrder)
cmds.setAttr("%s.rotateOrder"%group, rotOrder)
#add the controls and groups to lists to keep their order
ctrlList.append(ctrl)
groupList.append(group)
#parent up the groups and controls correctly
for i in range(chainSize-1, 0, -1):
cmds.parent(groupList[i], ctrlList[i-1])
评论列表
文章目录