Skip to content Skip to sidebar Skip to footer

Maya: Connect Two Joint Chains With Parent Constraint

So here is a snipit of an IK spine builder I've been working on. I've figure out how to make lists to duplicate the bound into an IK chain, what I've got stuck on however is I want

Solution 1:

Here's an example that will create 2 separate joint chains from scratch, then applies a parent constraint to each joint so that one chain drives the other:

import maya.cmds as cmds

joint_count = 10# Create 1st joint chain 'a'.
chain_a = [
    cmds.joint(position=[0, i * -2 + ((joint_count - 1) * 2), 0], name="a#")
    for i inrange(joint_count)]

cmds.select(clear=True)  # Need to clear selection so the next chain doesn't accidentally parent to chain a.# Create 2nd joint chain 'b'.
chain_b = [
    cmds.joint(position=[0, i * -2 + ((joint_count - 1) * 2), -10], name="b#")
    for i inrange(joint_count)]

# Use `zip` to iterate through both lists at the same time.for jnt_a, jnt_b inzip(chain_a, chain_b):
    cmds.parentConstraint(jnt_a, jnt_b, maintainOffset=True)  # Constraint b->a

The main idea is that you get 2 lists each with their own joints. You then pass those 2 lists to zip, so that when you iterate through it, it will first go through both 1st joints, then both 2nd joints, and so on.

To get this to work correctly you must make sure both lists have the same length, and both are using the same joint order. That way you don't have to hard-code anything and instead can do it procedurally (for example you can change joint_count to whatever number and it will still work).

You actually don't even need to use zip and can achieve the same thing by replacing the ending like this:

for i inrange(len(chain_a)):
    cmds.parentConstraint(chain_a[i], chain_b[i], maintainOffset=True)  # Constraint b->a

Though using zip feels more 'pythonic'.

Post a Comment for "Maya: Connect Two Joint Chains With Parent Constraint"