Hey there,
I'm having a small problem and somehow I can find a solution on the Internet. I'm trying to iterate over an array of objects and display face count with a for loop (not for in loop).
I tried various syntax's but somehow I am not able to save the face count into a integer variable, what am I doing wrong?
string $pObjs[] = `ls -sl`; //list selection<br>$objCount = size($pObjs); //object count<br><br>for( $i=0; $i<$objCount; $i++ ){<br> int $facecount = polyEvaluate -f $pObjs[$i];<br> print ($facecount);<br>}<br>
output:
// Error: int $facecount = (polyEvaluate -f $pObjs[$i]);
//
// Error: Line 5.35: Invalid use of Maya object "polyEvaluate". //
// Error: int $facecount = (polyEvaluate -f $pObjs[$i]);
//
// Error: Line 5.43: Invalid use of Maya object "f". //
Replies
Instead of this:
int $facecount = polyEvaluate -f $pObjs[$i];
it goes like this:
int $facecount = `polyEvaluate -f $pObjs[$i]`;
Since i am not in front of the computer i cant give it a test if that’s the only problem.
// Error: line 5: Cannot convert data of type int[] to type int. //
Convert the type to an array and you'll be good to go:
int $facecount[] = `polyEvaluate -f $pObjs[$i]`;
EDIT:
Had an odd thought that the command would return an array of ints when you had multiple objects selected. It would have meant that you could skip the setup/loop. Unfortunately when I was expecting 400, 16 I was instead given 416. So it summed them together to give me a single int in an array.
Does anyone have any idea why that's the case?
I'm not a MEL person I usually stick to Python so maybe this is just normal?
$facecount is a regular integer, getting a new value each time the loop runs, I don't get why maya thinks that it should be an array.
That's probably why `ls -sl` always returns an array for a single object also... As annoying as that is.
I found out that the real problem I was having is that I was using the single quote character (') instead of the accent grave character (`) when trying to type my own polyEvaluate command.