Form and Space

creating CG 3D since 2001

  • Connect @
  • Linked in
  • Vimeo
  • Twitter
Path Constraint version 0.2

Maya: Path Constraint v0.2

Matthew | April 19, 2012


This path constraint script is developed from my former multi-motion path script. It’s more developed, and is simpler for the user. To use it, select all the objects you’d like to path constrain, and then select the curve last. Run the tool. The order of your selection is the order along the path. Each object will be grouped, and the group will be path constrained using a standard motion path. The user’s objects can be transformed, while maintaining it’s connection to the path via the parent group. It’s simple rigging principles. 🙂 You can then edit the curve, and each object will maintain their percentage along the path.

Like most of my Maya tools, this tool is inspired by my usage of Softimage, and my desire to solve problems in a similar manner in both programs. For now, this tool is free to the public, so grab it while you can. When I’ve developed it far enough, I’ll sell it for a very nominal fee.

Path Constraint
version 0.2
Matthew L. Stoehr

This script will attach objects to a curve.

Simply select the objects, then select the curve last.

Selection order is the order of objects on the path, from 0 to 1 of the path U value.
Works best if the curve is drawn from the top view... (up vector problems)


proc mls_pathConstraint()

string $mySelection[] = `ls -selection`;
int $size = size($mySelection);
int $objCount = $size - 1;

/*----------------- Find the curve ---------------------*/
//if the node is a curve, don't group it, and use it for the namespace
//last in selection
string $path = $mySelection[$objCount];
//make the offset controller
spaceLocator -absolute -position 0 0 0 -name ($path + "_offset_00");
//collect all offset controllers, locator transforms, and find the most recently created locator
string $myOffsets[] = `ls -tr ($path + "_offset_*")`;
int $offsetsCount = size($myOffsets); 
string $recentOffset = $myOffsets[$offsetsCount-1];

/*---------------------- Make a group per object -----------------------*/
//psuedo: make a group for each selection, so it has the motion path, not the artist's objects.
for ($i = 0; $i < $objCount; $i++){
    select -r ($mySelection[$i]);
    //finds the pivot point of the selection, via query (-q)
    vector $v1 = `xform -q -t`;
    vector $v2 = `xform -q -sp`;
    vector $v3 = $v1 + $v2;    
    group -n ($path + "_motion_grp");
    //set the group's pivot to the object's pivot location
    xform -os -piv ($v3.x) ($v3.y) ($v3.z);
    //use the curve name for the namespace
//collect the new groups
string $myMotionGroups[] = `ls ($path + "_motion_grp*")`;

/*---------------------- Path Constraint -----------------------*/
float $offset = 0.0;
float $spacing = 1.0;
//objCount - 1 so the objects distribute along the entire curve.
float $divisions = $spacing/($objCount-1);

for($i=0; $i < $objCount; $i++){
    float $uLinearDistribution = $divisions * ($i+$offset);
    string $motion = `pathAnimation -f 1 -fm 1 -etu 0 -c $path $myMotionGroups[$i]`;
    string $source = $motion + "_uValue.output";
    string $destination = $motion + ".uValue";
    disconnectAttr $source $destination;
    setAttr ($motion + ".uValue") $uLinearDistribution;
    expression -s ($motion + ".uValue = "+ $uLinearDistribution +" + "+ $recentOffset +".translateX * 0.1") -o $motion;
    //expression -s ($motion + ".uValue = "+ $spacing +"/(" + $objCount + "*("+ ($i+1) +" + "+ $path + ".offset));") -o $motion;


/*----------------------- Group All to Organize the Outliner----------------*/
for ($i = 0; $i < $objCount; $i++){
    select -add ($myMotionGroups[$i]);
	//rename the motion groups to allow more objects to attach to the same path
    rename $myMotionGroups[$i] "_motion_grp_";
group -n ($path + "_grp_00");

select -r $path;

/*********************************** end ******************************************/

2 responses to “Maya: Path Constraint v0.2”

  1. KC Childers says:

    Sweet, I have the original you gave me somewhere, but guessing this is newer then that.

  2. Matthew says:

    Yes, much newer. There are several improvements.

Leave a Reply