[Closed] how to count polygones in selection ?
I write simple code to count geometry but it’s base on polyop.getNumFaces and I before I’ll count faces I have to transform mesh in to editable polygone and determine if geometry is not target object or particle system which is extreme slow if I have more then 500 object in view. Is there any way to count polygones in selection without transforming geometry in to polygones fast?
I would be v.grateful for help because I fight with this for long time.
thanks, work great, but I can’t figure out how to use it in selection, i tried like this but won’t work:
numgeofacesmdxray=#()
if isProperty selection[1] “mesh” != null do
(
for o in selection do
(
ot=o[1].mesh.faces.count ; append numgeofacesmdxray ot
totalfaces=totalfaces+ot
)
)
totalfaces=totalfaces as string
messagebox totalfaces
numgeofacesmdxray=numgeofacesmdxray as string
messagebox numgeofacesmdxray
I need it to for 2 variants:
1 – count all faces in selection
2 – if object in selection have more then x faces do something
Please can You tell me how to use it.
i think that the using undefined null variable instead of undefined is not a good idea too
This will collect nuber of faces (not polygons) of any selected mesh object
for o in selection where isProperty o #mesh != undefined collect o.mesh.faces.count
null or false seams to work this same. I also tried this but if there are different then goemetry object code indicate 0 faces:
select objects
fac=0
for n in selection where superclassof o == geometryClass and canConvertTo o Editable_Mesh and classof o !=Targetobject do
(
if isProperty selection[1] “mesh” != false do fac=fac+selection[1].mesh.faces.count
)
fac=fac as string
messagebox fac
fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
for o in nodes where isProperty o #mesh != undefined do
if (cnt = o.mesh.faces.count) > limit do format "object:% facecount:%
" o.name cnt
)
checkFacesCount selection limit:1000
i wish i could say “work fine”. It work fine:) but … there is always but
it inicate 0 faces when objects are grouped so I used function to open groups and test it on real-life scene and code indicate 0 polygones because often groups are inside groups inside groups. I modyfied your code a bit:
fac=0
for n in selection where superclassof n == geometryClass and canConvertTo n Editable_Mesh and classof n !=Targetobject do
(
if isProperty selection[1] “mesh” != false do fac=fac+selection[1].mesh.faces.count
)
and to ungroup object:
fn ungroupAll objs =
(
group_arr = for o in objs where isValidNode o AND isGroupHead o collect o
with redraw off
(
for o in group_arr do
(
setGroupOpen o true
--ungroup o
)
)
)
ungroupAll objects
but don’t work in practice
This work fine for me. Even if the group is closed
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 format "object:% facecount:%
" o.name cnt
)
checkFacesCount selection limit:1000
And even shorter example
fn checkFacesCount nodes limit: = if nodes.count != 0 do
(
for o in nodes where isProperty o #mesh and \
(cnt = o.mesh.faces.count) > limit do format "object:% facecount:%
" o.name cnt
)
checkFacesCount selection limit:1000
null or false seams to work this same.
eh ?
IsProperty returns true or false and null is not the same as false !
try the following in the listener
null == false
null == true
null == undefined
null in mxs is just another undeclared varible and always returns undefined.
We only need “true” statement here ei. (isProperty $ #mesh)
the null is just an undefined variable which equals undefined until it’s not defined