View Full Version : Selected polys doubled?

07-19-2003, 04:10 AM
Hi scripters,

I am writing my first script and it involves checking the points and polygons selected by the user...


A bit further along I calculate the number of selected polys from adding up the values in PolyCnt array, items 1 through 6...

Strangely I always seem to get twice as many polygons as selected... It is as if both sides are selected by default...

Is this expected behaviour or viewport related... The selected polygons (Set in lower screen is correct)...

I can just divide by two get the right number, but I wonder... ;)

Tom Speed
07-19-2003, 12:23 PM
I'm not sure 'pointCnt=selmode(USER)' is legal :) .. Never tried it to be honest.

Also, polyCnt=polycount() returns more than just a poly count, it returns an array!

From LScriptReference.PDF , Chapter 13, Page 75:


polycount() returns six (6) integer elements,
1 total number of selected polygons
2 total number of selected polygons that contain only
one point.
3 total number of selected polygons that contain only
two points.
4 total number of selected polygons that contain only
three points.
5 total number of selected polygons that contain only
four points.
6 total number of selected polygons that contain more
than four points.
You can use pntCnt=pointcount() at any time though.

Try this instead:

polyCnt=polydata[1]; // the 'actual' number of selected polygons!

if(polyCnt<1 && pointCnt<1) // nothing selected, no need to continue?
error("Nothing selected!");

// else continue in USER mode

You have to be careful with selection modes as USER mode will report the global count if nothing is selected. Use selmode(DIRECT), then do your count tests, this will give an exact count, then just hop over to USER mode if your script carries on (if there's 'something' selected)


07-19-2003, 06:33 PM
Yes it is legal, selmode returns a value...

Thanks Tom, I had read all of that ;)

I undestand the selection modes and yes I used the array and check the for the number of polygons in each entry, however I had read the 6 value array info too quickly... for some reason I thought it was:

1 point polygons
2 ,, ,,
3 ,, ,,
4 ,, ,,
5 ,, ,,
6 ,, ,, and higher...

So I just need to check the first element of the array.... which are the selected points... Thx! Explains why they were double (index 1 of the array plus index 5 for 4 points polygons), the rest were empty... I was testing with a simple box.

The next step is to have some of the selected polygons deselected, so that will be the next challenge... ;)

Thanks again!