一半君的总结纸

听话只听一半君

#08 How do I find the Shape node of a Transform? Or the Transform of a Shape node?

To get the list of Shape nodes from a Transform:

proc string[] getShapes( 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;
}

Note that this returns a string array, as it is possible for a single transform to be the parent of multiple shape nodes.

To get the Transform from a Shape node:

proc string getTransform( string $shape )
{
   string $transform = "";

   if ( "transform" != `nodeType $shape` )
   // If given node is already a transform, just pass on through
   {
      string $parents[] = `listRelatives -fullPath -parent $shape`;
      $transform = $parents[0];
   }

   return $transform;
}

Related How-To’s

11 May 2003

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: