MEL How-To #60

Back · Previous · Next Maya

How do I determine if a transform is a Group node?

A "group" node is simply an empty transform, often with other transforms (and their associated child shapes) as children.

So the first thing to confirm is that the node is in fact a transform node:

if ( `nodeType $possibleGroupNode` != "transform" )
{
  print ( $possibleGroupNode + " can't possibly be a group node.\n" );
}

Next I would suggest the use of the ‘listRelatives’ command to see if the transform has any associated shape nodes of its own:

string $possibleGroupNode = "group1";

if ( size( `listRelatives -shapes $possibleGroupNode` ) == 0 )
{
  print ( "Transform without Shape: Possibly a group node.\n" );
}
You could enhance the query to see if the node has only other transforms as children:
int $onlyTransforms = true;

string $groupChildren[] = `listRelatives -children $possibleGroupNode`;

if ( size( $groupChildren ) == 0 )
{
  print ( "Empty transform.\n" );
}
else
{
  // iterate children and see if they're all transforms themselves...
  for ( $child in $groupChildren )
  {
    if ( `nodeType $child` != "transform" )
    {
      $onlyTransforms = false;
      break;
    }
  }
}

if ( $onlyTransforms )
{
  print ( "Transform has only other transforms as children.\n" );
  print ( $possibleGroupNode + " may be considered a Group node.\n" );
}
else
{
  print ( $possibleGroupNode + " is not a simple Group node.\n" );
}

Tuesday, March 27, 2001