Search code examples
pythonmaya

Selecting Joints in hierarchy one at a time


I have this code

joint_name = cmds.ls(sl=1)[0]
circle_name = cmds.circle(name = joint_name + "_CTL", nr=(1, 0, 0) )
group_name = cmds.group(name = joint_name + "_OFFSET")
cmds.select(joint_name, group_name)temp_constraint = cmds.parentConstraint()
cmds.delete(temp_constraint)
cmds.select(circle_name, joint_name)
cmds.pointConstraint()
cmds.orientConstraint()

When you select a joint and run this code you will get a circle that will control that joint. While going down the hierarchy you have to select that joint and then run the code.

How would I be able to have all the joints to have circles controlling them without having to go through the outliner selection a joint?


Solution

  • run this on your chain of joint :

    for x, joint_name in enumerate(cmds.ls(sl=1, dag=True, type='joint')):
        circle_name = cmds.circle(name = '{}_CTL{:02d}'.format(joint_name,x), nr=(1, 0, 0) )
        group_name = cmds.group(name = '{}_OFFSET{:02d}'.format(joint_name,x))
        cmds.select(joint_name, group_name)
        temp_constraint = cmds.parentConstraint()
        cmds.delete(temp_constraint)
        cmds.select(circle_name, joint_name)
        cmds.pointConstraint()
        cmds.orientConstraint()
    

    Note that instead of use select, you could feed pointConstraint : cmds.pointConstraint(circle_name, joint_name, n='something')