ELEMENT WITH HIGHEST POLYGONS NUMBER COUNT IN ONE OBJECT

Hello guys,
It has been a while since I start looking for this solution, but nothing.

I need to find and select the element with the highest poly number count in one object. There is no poly count target number, it is totally aleatory.

Another approach would be detaching the elements into objects and find the object with the highest poly number count in this object array selection.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

This is will count the faces if the object is converted to editable mesh.

(
	fn GetMeshElementsCount node =
	(
		elementMaxFacesCount = 0
		tmesh = snapshotasmesh node
		faces = #{1..tmesh.numfaces}
		verts = for v = 1 to tmesh.numverts collect #()
		cnt = 0
		for j in faces do
		(
			f = getface tmesh j
			for k = 1 to 3 do append verts[f[k]] j
		)
 
		for i in faces do
		(
			element = #(i)
			for j in element where faces[j] do
			(
				faces[j] = false
				f = getface tmesh j
				for k = 1 to 3 where verts[f[k]] != undefined do
				(
					join element verts[f[k]]
					verts[f[k]] = undefined
				)
			)
			if elementMaxFacesCount < element.count do elementMaxFacesCount = element.count
		)
		elementMaxFacesCount
	)
 
	GetMeshElementsCount selection[1]	
)
rvidal's picture

Thank you miauu, But it is

Thank you miauu,
But it is counting a very high face number, very different from the elements or object...

How would I continue the script selecting the element with this count number retrieved?

Anybody can help me with that?

miauu's picture

.

(
	fn GetMeshElementsCount node =
	(
		elementMaxFacesCount = 0
		elementFacesArr = #{}
		tmesh = snapshotasmesh node
		faces = #{1..tmesh.numfaces}
		verts = for v = 1 to tmesh.numverts collect #()
		cnt = 0
		for j in faces do
		(
			f = getface tmesh j
			for k = 1 to 3 do append verts[f[k]] j
		)
 
		for i in faces do
		(
			element = #(i)
			for j in element where faces[j] do
			(
				faces[j] = false
				f = getface tmesh j
				for k = 1 to 3 where verts[f[k]] != undefined do
				(
					join element verts[f[k]]
					verts[f[k]] = undefined
				)
			)
			if elementMaxFacesCount < element.count do
			(
				elementMaxFacesCount = element.count
				elementFacesArr = element
			)
		)
		format "Max faces: %\n" (elementMaxFacesCount / 3)
		(elementFacesArr as bitarray)
	)
 
	elementFacesBA = (GetMeshElementsCount selection[1])
	setFaceSelection selection[1] elementFacesBA
)
rvidal's picture

Thank you miauu, But it is

Thank you miauu,
But it is counting a very high face number, very different from the elements or object...

How would I continue the script selecting the element with this count number retrieved?

Anybody can help me with that?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.