March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #58

Back · Previous · Next Maya

How do I determine how many CVs are in a NURBS Curve or Surface?

To determine how many CVs are in a curve:

  string $curve = "curveShape1";

  int $numSpans = `getAttr ( $curve + ".spans" )`;
  int $degree   = `getAttr ( $curve + ".degree" )`;
  int $form     = `getAttr ( $curve + ".form" )`;

  int $numCVs   = $numSpans + $degree;

  // Adjust for periodic curve:
  if ( $form == 2 ) $numCVs -= $degree;

To select all CVs in this curve:

  select ( $curve + ".cv[0:" + ($numCVs-1) + "]" );

  // or simply...
  select ( $curve + ".cv[*]" );

To determine how many CVs are in a surface:

  string $surface = "nurbsSphereShape1";

  int $numSpansU = `getAttr ( $surface + ".spansU" )`;
  int $degreeU   = `getAttr ( $surface + ".degreeU" )`;

  int $numSpansV = `getAttr ( $surface + ".spansV" )`;
  int $degreeV   = `getAttr ( $surface + ".degreeV" )`;

  int $formU     = `getAttr ( $surface + ".formU" )`;
  int $formV     = `getAttr ( $surface + ".formV" )`;

  int $numCVsU   = $numSpansU + $degreeU;
  // Adjust for periodic hull:
  if ( $formU == 2 ) $numCVsU -= $degreeU;

  int $numCVsV   = $numSpansV + $degreeV;
  // Adjust for periodic hull:
  if ( $formV == 2 ) $numCVsV -= $degreeV;

  // Total CVs is U count times V count.
  int $numCVs = $numCVsU * $numCVsV;

To select all CVs in this surface:

  select ( $surface + ".cv[0:" + ($numCVsU-1) + "][0:"
                               + ($numCVsV-1) + "]" );

  // or simply...
  select ( $surface + ".cv[*][*]" );

Related How-To's

29 Jan 2005