View Full Version : How to query the number of polys on the current selected object?
GeoffClark 06-19-2009, 06:05 AM Hello!
For the life of me, I can't find a MEL command that will return the number of polygons in a selected poly object. It must return an integer, to be used in a while () statement loop.
In other words:
while (number of polys in the selected object ) > 1)
{
do some stuff;
}
god it's so basic but I cannot find it.
Thanks!
|
|
siproductions
06-19-2009, 06:50 AM
Took me a sec to find this.
polyEvaluate -f objectName;
Cheers,
Simon
GeoffClark
06-19-2009, 04:01 PM
Simon,
Thanks for the reply. I, too have seen the polyEvaluate -f command, but the problem with it is that its return type an array, not a single integer value.
Perhaps I'm just needing a pointer on how to phrase the while statement so that the polyEvaluate command is properly evaluated. It's all in the syntax, I think.
while (`polyEvaluate -f $selectedObj[0]` > 6)
{}
does not work because it is an array. How do you have the first index of the polyEvalute command be returned in the while statement, so that the result is evaluated on each loop interation?
Thanks,
Geoff
dr.rastaman
06-19-2009, 04:21 PM
Hi,
try it like this:
int $numFaces[] = `polyEvaluate -f $selectedObj[0]`;
while( $numFaces[0] > 6 ) {
... do something ..
}
Cheers
Rico
GeoffClark
06-19-2009, 05:23 PM
Rico,
That , too , had occurred to me. That code becomes an infinite loop , because $numFaces[] never gets re-evaluated. So the number of faces never drops. That's why I wanted to backquote the command in the while statement.
If you put the PolyEvaluate command within the loop, then the variable is never initiated for the while statement. It's a tricky issue.
siproductions
06-19-2009, 06:00 PM
This should work: There's probably a better/cleaner way of recasting the array to the int but it gets the job done.
Cheers,
Simon
$Array = `polyEvaluate -f pSphere1`;
int $test = $Array[0];
$i = 0;
while ($i < $test)
{
print $i;
$i = $i + 1;
}
claydough
06-20-2009, 06:37 AM
try size.
with a single or multiple poly object selection fer example:
{
string $meshSelections[] = `filterExpand -sm 12`;
for ( $m in $meshSelections ) {
// size the number of faces ( expanded )
int $numberOfPolys = size(`filterExpand -sm 34 -expand 1 ( $m+ ".f
" )`);
print ( $numberOfPolys+ "\n" );
}
}
while...
string $meshSelections[] = `filterExpand -sm 12`;
while ( size(`filterExpand -sm 34 -expand 1 ( $meshSelections[0]+ ".f
" )`) > 1) {
print ( size(`filterExpand -sm 34 -expand 1 ( $meshSelections[0]+ ".f
" )`) + "\n" );
// insert non-infinite looping while logic here
}
claydough
06-25-2009, 05:28 AM
same with non infinite looping while logic fer example:
( safe evaluation proof )
{
string $meshSelections[] = `filterExpand -sm 12`;
while ( size(`filterExpand -sm 34 -expand 1 ( $meshSelections[0]+ ".f
" )`) > 1) {
int $currentFaceSize = size(`filterExpand -sm 34 -expand 1 ( $meshSelections[0]+ ".f
" )`) ;
print ( $currentFaceSize+ " is the number of faces currently on the mesh \n" );
string $lastFace = $meshSelections[0]+ ".f["+ $currentFaceSize+"]";
delete $lastFace;
}
}
Robert Bateman
06-25-2009, 09:59 AM
Just get the size of the faces array.
getAttr -s ($transform+".fc")
or...
getAttr -s ($mesh+".fc")
both work (assuming the transform has a child mesh).
claydough
06-25-2009, 03:26 PM
Just get the size of the faces array.
getAttr -s ($transform+".fc")
or...
getAttr -s ($mesh+".fc")
both work (assuming the transform has a child mesh).
Nice! Thanks Robert
CGTalk Moderation
06-25-2009, 03:26 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.