Loop over selected objects and print their polygon (triangle) count

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm writing a script that with a selected number of objects, writes out the name of each selected object along with it's individual poly count. So far so good. Only I can't figure out how to do that on an object by object basis. The poly count is added in total and not done individually.
Here's what I have
import maya.cmds as cmds
import sys
# List all selected objects
selectAll = cmds.ls( selection = True )
if len(selectAll) < 1:
print "No selection"
else:
for obj in selectAll:
print obj
# query the number of faces
faces = cmds.polyEvaluate( f = True )
# query the number of triangles
triangles = cmds.polyEvaluate( t = True )
print "Selected triangles: " + str(triangles)
results = "Selected triangles: " + str(total_faces)
sys.stdout.write(results)