MEL How-To #81

Back · Previous · Next Maya

How do I find the deformers influencing an object?

To find the skinClusters (smooth bind) and its joints influencing a polymesh:

findRelatedSkinCluster myObject;
// Result: skinCluster1 //

skinPercent -q -t skinCluster1 "myObject.vtx[*]";
// Result: joint1 joint2 joint3 joint4 //

For a NURBS object:

findRelatedSkinCluster myNurbsObject;
// Result: skinCluster2 //

skinPercent -q -t skinCluster2  "myNurbsObjects.cv[*]";
// Result: joint5 joint6 joint7 joint8 //

To find clusters, jointClusters (rigid bind), joints and lattices influencing an object:

proc string getShape( string $xform )
{
  string $shapes[];

  $shapes[0] = $xform;

  if ( "transform" == `nodeType $xform` )
  // If given node is not a transform, assume it is a shape 
  // and pass it through
  {
    $shapes = `listRelatives -fullPath -shapes $xform`;
  }

  return $shapes[0];
}

// Returns an array of the 'cluster', 'jointCluster',
// or 'lattice' nodes influencing the specified objects.
// Note that a 'jointCluster' is also a 'cluster'.
// $obj: The object to query.
// $deformerType: "cluster", "jointCluster" or "lattice".
global proc string[] findRelatedDeformer( string $obj,
                                          string $deformerType )
{
  string $related[];

  string $longName = getShape( $obj );
  string $shortName[] = `ls -sn $longName`;

  string $deformers[] = `ls -type $deformerType`;

  for ( $deform in $deformers )
  {
    string $geometry[];

    switch ( $deformerType )
    {
        case "cluster":
        case "jointCluster":
        {
            $geometry = `cluster -q -g $deform`;
            break;
        }

        case "lattice":
        {
            $geometry = `lattice -q -g $deform`;
            break;
        }
    }

    for ( $g in $geometry )
    {
        if ( ( $g == $longName ) || ( $g == $shortName[0] ) )
        {
          $related[`size $related`] = $deform;
        }
    }
  }

  return $related;
}

// Returns the 'joint' nodes related to a 'jointCluster',
// or the 'clusterHandle' nodes related to a 'cluster'.
// or the 'joint' nodes related to a 'skinCluster'.
global proc string[] findDeformerDAGs( string $deformerNode )
{
    string $DAGs[];

    string $connect[] = `listConnections -source true
      ( $deformerNode + ".matrix" )`;

    for ( $c in $connect )
    {
        $DAGs[`size $DAGs`] = $c;
    }

    return $DAGs;
}

29 March 2002