Evaluate render mesh polycount in python

Hi All!
I need to find a way to evaluate the complexity of a file.
This will be part of a script that I am running from cmd.

I was thinking to check the polycount of the render mesh at first, but I can-t find an easy way to do it in python.

Any hints?

Thanls in advance

Hi @Pitti,

Have you tried using Rhino’s PolygonCount command?

– Dale

Hi @dale , yes I solved it in that way.

But… I had to extract the Number from the string, not exactly elegant :sweat_smile:

By the way this is how I solved it:

Import re
Import rhinoscriptsyntax as rs

rs.ClearCommandHistory()
rs.AllObjects(True)
rs.Command("_PolygonCount")
CH= str(rs.CommandHistory())
start = ‘be’
end = ’ total’
polycount = CH[CH.find(start)+len(start):CH.rfind(end)]
total = int(re.sub("[^0-9]", “”,polycount))

on mesh.Faces you can also find QuadCount and TriangleCount ( MeshFaceList Class )

Instead of asking per brep face you could also just do loop over all RhinoObjects and use RhinoObject.GetMeshes instead:

import scriptcontext as sc
import Rhino

tris = 0
quads = 0

for o in sc.doc.Objects:
    meshes = o.GetMeshes(Rhino.Geometry.MeshType.Render)
    for m in meshes:
        tris += m.Faces.TriangleCount
        quads += m.Faces.QuadCount

@nathanletwory Niceee!
I will test which one is faster…