MEL How-To #03

Back · Previous · Next Maya

How can a get a list of all vertex or edge components that are associated with a polymesh face? (or vice versa)

There's a nice little hidden (well, non-obvious anyway) MEL command that came to light with Quang Tran's edgePath/facePath tools:

polyListComponentConversion

It returns a converted selection list, so all you need to do is assign the results of this command to a string array:

// Vertices associated with face
string $vtx[] = `polyListComponentConversion -toVertexFace pCube1.f[5]`;
// Result: pCube1.vtx[0] pCube1.vtx[2] pCube1.vtx[4] pCube1.vtx[6] //

// Edges associated with face
string $edge[] = `polyListComponentConversion -toEdge pCube1.f[1]`;
// Result: pCube1.e[1:2] pCube1.e[6:7] //

// Vertices associated with edge
string $vtx[] = `polyListComponentConversion -toVertex pCube1.e[1]`;
// Result: pCube1.vtx[2:3] //

// Faces associated with vertex
string $face[] = `polyListComponentConversion -toFace pCube1.vtx[1]`;
// Result: pCube1.f[0] pCube1.f[3:4] //

The "Old Way"

I originally used a "brute force" procedure and parsed the results of the 'listAttr' command to get the vertices associated with a face.

proc int[] facetVertices( string $facet )
{
   int $vertices[];
   int $numVertices = 0;

   string $attr[] = `listAttr $facet`;

   for ( $i = 0; $i < size( $attr ); $i+=4 )
   {
      $vertices[$numVertices++] = match( "[0-9]+", $attr[$i] );
   }

   return $vertices;
}

Related How-To's

Thursday, January 18, 2001