Printing A Face Normal To A File

Hello world,

I am setting a face to have a face normal,

polySetToFaceNormal;

I am trying to query a face to get the face normal from "polyInfo -fn polySurface12.f[0]"

This returns : "// Result: FACE_NORMAL 0: -0.688109 0.000000 -0.725608 //

so far so good.

but when I try to put this result into something like

$zxc = polyInfo -fn polySurface12.f[0];

then I get this

// Error: Cannot convert data of type string[] to type float. //

I am surely doing something wrong.

can anyone help.

thank you
ken

The error comes up becauce polyInfo returns a string, not a float, so you should instead use:

CODE
string $zxc[] = polyInfo -fn polySurface12.f[0];

And because polyInfo returns a string and not a vector directly, you will have to tokenize that string to remove all the unwanted characters.
You can use Bryan Ewert's function to do this:

CODE
proc vector translatePolyInfoNormal( string $pin )
{
  vector $normal;
  float $x;
  float $y;
  float $z;

  string $tokens[];
  int $numTokens = tokenize $pin " " $tokens;

  // Make sure we're looking at polyInfo data:
  if ( ( $numTokens > 3 ) && ( $tokens[0] == "FACE_NORMAL" ) )
  {
    // Maya performs data-type conversion here.
    $x = ($tokens[$numTokens-3]);
    $y = ($tokens[$numTokens-2]);
    $z = ($tokens[$numTokens-1]);

    $normal = <>;

    // Normalize it.
    $normal = unit $normal;
  }

  // Return it.
  return $normal;
}

For more info: http://www.ewertb.com/maya/mel/mel.php?howto=05

Thank you Thank you Thank you,

This example worked out great so far.

I am working out the fact that every once and a while I will get an errant value.

but that is for another day.

again thank you very much.

-ken