PDA

View Full Version : Selected polys doubled?



richpr
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...

pointCnt=selmode(USER);
editbegin();
...
polyCnt=polycount();
...
editend();


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()

polycount() returns six (6) integer elements,
representing:
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:



selmode(DIRECT);
polydata=polycount();
polyCnt=polydata[1]; // the 'actual' number of selected polygons!
pointCnt=pointcount();

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

// else continue in USER mode
selmode(USER);
...




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)

Tom

richpr
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!