Notifications
Clear all

[Closed] how to count polygones in selection ?

null in mxs is just another undeclared varible and always returns undefined.
We only need “true” statement here ei. (isProperty $ #mesh)

but that’s not what you first coded !? what i was referring too was this

if isProperty selection[1] "mesh" != null do selection[1].mesh.faces.count
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

I made a mistake there.
@kredka never says at the beginning what exactly wants. After few posts he knows.
And then is easy to correct the code.

And I guess we have not done here. Probably something is not right

function work strange.
So I have 4 objects on scene one with 92 poly, 36, 6 and one with 18336. Limit is set on 1000, function should deselect objects with less then 1000 but objects with 18336 nad 36 poly are still selected. I check it on different scenes and it also work strange.
take a look on this code and on picture in attachment , I don’t get it. It should deselect objects with less then 1000 faces it this case. I spent on few ours and still don’t work.

select objects
fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
for o in nodes where isProperty o #mesh do
(
if (cnt = o.mesh.faces.count) < limit do deselect o

)
)
checkFacesCount selection limit:1000

I knew it You don’t listen. Tell me exactly what do you want to achive. I can write code for you.

fn checkFacesCount nodes limit: = if nodes.count != 0 do
  (
  	 deselect (for o in nodes where isProperty o #mesh and o.mesh.faces.count < limit collect o) 
  )
  checkFacesCount selection limit:1000

Branko, I already own you veryyy big beer. This one work fine for me.
I work on this one so long that I may not think straight tonight:)

  • So I have two issues.
    One – You already solved – I work on tool which gonna speedup viewport fps and I want put optymize modyfiers on models with more faces then xxx(depend on user preferences). This one is already done thanks to You. Case closed,dismissed(I hope)

Second – this one gives me hard time – I want count all polygons in selection(just to get information, and also determine if there is mesh object with 0 faces on it – ghost mesh). It’s not as ease for me as simple it sound (maybe it not sound simple, I don’t know). I already created 4 versions of such a code but it seams there is always some obstacle to count it. First of all – even if code work on test – models then working on big scene with all tons of everything is different story. First of all: geometry type is also particle system, camera target, foliage(polyop.getNumFaces dont like it – it must be editable poly), etc. Then there is problem with opening groups some how, some times there is 3 or more groups closed inside one another and sometimes I can’t open all of them. Then sometimes(I know I used sometimes third time, it’s late) code just stop counting on some spline element or some x element don’t know why. Another version which is the most preside take to long time to calculate. There is always something, I need just code that will be able to count polygones in selection. If it,s piece of cake for you then it would be fantastic if you could drop me few lines of code, if this is to much thank you anyway. Ok it’s late time to bed. There is a lot of code to produce tomorrow.

5 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

We can continue tomorrow then.

(@denist)
Joined: 11 months ago

Posts: 0

#1 if you want to speedup view redraw you should care about display issues (not geometry)
#2 why a mesh with 0 faces but with 1000K vertices is not a ‘ghost’?

(@gazybara)
Joined: 11 months ago

Posts: 0

#2| Meshes with more then 0 verts can be used with Lattice modifier or to draw some polygons maybe and therefore we can say that we need these meshes for later use.

(@denist)
Joined: 11 months ago

Posts: 0

maybe… and also maybe all 1000K mesh’s faces have ZERO area. … there could be many other ‘maybe’.
so, we have to use the right criterion of ‘light’ and ‘heavy’ mesh. the number of faces doesn’t look for me right.

(@gazybara)
Joined: 11 months ago

Posts: 0

Yes you are absolutely right.
“Maybe” will always be present until we know what the author really wants

fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
      	deselect (for o in nodes where isProperty o #mesh and o.mesh.faces.count < limit collect o)
)
      
only four lines of code but at least four things have to be fixed there ;)

edited…
the hint:
lines #2 and #4 are good.

fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
	clearselection()
	select \
	(	
		for o in nodes where isProperty o #mesh and canConvertTo o Editable_Mesh collect
		(
			case of
			(
				(o.mesh.faces.count == 0): (delete o ; dontcollect)
				(o.mesh.faces.count > limit):o
				default: dontcollect
			)
		)
	)
)
 -- remove "ghosts" meshes and select only these which have more then 500 faces
 checkFacesCount (selection as array) limit:500
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Or shorter version

fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
	clearselection()
	select \
	(	
		for o in nodes where isProperty o #mesh and canConvertTo o Editable_Mesh collect
		(
			if (val = amin #(o.mesh.faces.count,limit)) == limit then dontcollect else (if val == 0 then (delete o ; dontcollect) else o)
		)
	)
)
-- remove "ghosts" meshes and select only these which have more then 500 faces
checkFacesCount (selection as array) limit:500

I appreciate your patience:) So I guess now it’s two beers already.
By “empty mesh” I was trying to determine if there are some objects on scene which are unnecessary – I know there is always some but … but I need just info about potencial garbage, and it’s very unlikely to have mesh with 0 poly or vertex which is necessary on scene , I don’t have to kill such a objects, just get info, and put this object to array and it work great with your functions. What I can’t achieve is part 2.

Now part 2.
All codes work fine, no problem with this but it’s really stupid because your code count faces but I can’e get it how to take information about all polygones in selection from your function. I have it right in front of my eyes and I can’t figure this out. I know is line:

o.mesh.faces.count

but I can’t take it from your function, so I tried this:

allpoly=0
s=(for o in selection where isProperty o #mesh and classof o !=PF_Source and o.mesh.faces.count >0 collect o)
for o in s do
(

allpoly=allpoly+o.mesh.faces.count

)

and here is problem because if this code will encounter PF_source or superspray it crash in spite of I excluded all kind of particles, helpers and all kinf of non-mesh objects. It’s super strange because I created box and Particle flow and in spite particle flow is excluded from selection code still want perform operation on this. How to just get info about poly amount in selection? just this.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Why do you need to know how many polygons have object if you used for some viewport process? Are face count is not enough. I sad this because calculating polygons in mesh can be slow. Even “Show Statistics” shows number of face (not polygons).

You not need to use “classof o != PF_Source”. Just use “canConvertTo o editable_mesh”.
Also you can replace “o.mesh.faces.count” with “o.mesh.numfaces” because is the same.
U can consider “o.mesh.numverts” if you want to know number of verts.

thanks, I need info for my tool to gather all information in one place- it can be faces or polygones, no matter but I just want count it to inform user how have is scene or objects.

This is the very slow method how to calculate polygon count of selected mesh.
Maybe someone can optimize this or write better code

fn meshPolyCount obj =
(
	local polyArr = #(), moGetPolyByEdge = meshop.getPolysUsingEdge
	for face = 1 to obj.numfaces do
	(
		for edge = 1 to 3 where (getedgevis obj face edge) do appendIfUnique polyArr ((moGetPolyByEdge obj #{(((face-1)*3)+edge)}) as string)
	) ; polyArr.count
)
meshPolyCount $.mesh

you guys are overcomplicated everything…
first of all we have to filter only objects that can be converted to mesh (geometry primitives, editable meshes, editable polys, polymesh objects, nurbs, patches, and shapes)… if don’t need shapes we can exclude them specially

so the list of nodes


nodes = for node in selection where canconvertto node Ediatble_Mesh collect node 

next is to get number of faces…
if a node is Editable_poly or PolyMeshObject it returns the number of polys, other way the number of tri-faces

well…


(
for node in nodes do
(
	class = classof node
	numfaces = if class == Editable_Poly or class == PolyMeshObject then node.numfaces else node.mesh.numfaces
	format "name:% class:% numfaces:%
" node.name class numfaces
)
)

that’s it.
because there is no sense to add apples to oranges we have to calculate the summary of all tri-faces. so the all faces are


numfaces = 0
for node in selection where  canconvertto node Ediatble_Mesh do numfaces += node.mesh.numfaces
numfaces 

that is all

3 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

I agree but he asked about mesh number of polygons. I posted solution above but is to slow even for single object.

(@denist)
Joined: 11 months ago

Posts: 0

who cares about number of polygons of not-polygon object?

(@gazybara)
Joined: 11 months ago

Posts: 0

Exactly. I asked the same question

Page 2 / 3