So far I have written the following code. I am super new to python

class polygon(object):
    def__init__(self, edge, face, vertex='')
        self.edge = edge
        self.face = face
        self.vertex = vertex
        self.tetrahedron = tetrahedron

a = polygon('6', '4', '4', tetrahedron)
print a.edge, a.face, a.vertex, a.tetrahedron
print a  

Also How can find the mesh module in Python? I am using spyder and I cant find it in the library. Please help if anyone can.


You can get the active object for instance:

ob = bpy.context.object

And get its data (if it's a mesh object, the mesh datablock):

me = ob.data

Mesh element counts:

len(me.polygons) # faces

Vertex count of a single face:

  • $\begingroup$ Thank you very much. However, everytime I put bpy it says it is not recognized or no such module found. Please pardon my lack of knowledge. I started using python 2 days ago for the first time. How can fix that? I am using spyder IDE. But thank you a lot for your help $\endgroup$
    – user5184
    Jul 12 '14 at 19:42
  • 1
    $\begingroup$ You need to run it inside of Blender, which comes with its own Python 3.x and the bpy module. $\endgroup$
    – CodeManX
    Jul 12 '14 at 20:24
  • $\begingroup$ So can I use the same code to find vertices and faces in like tetrahedron? $\endgroup$
    – user5184
    Jul 12 '14 at 21:27
  • $\begingroup$ what about find all vertices count in the scene? $\endgroup$
    – four two
    Feb 24 '20 at 16:40
  • 1
    $\begingroup$ @fourtwo It's pointless to sum up the vertices of all meshes in a scene IMO, because it's ill-defined. Should it include invisible objects, instantiated groups, etc.? And if you want to include modifiers then you either have to apply them (e.g. using a temporary mesh object) or rely on what Blender shows in the status bar (bpy.context.scene.statistics(bpy.context.view_layer) but beware, this is mode dependent! Old script which ensures object mode: github.com/CoDEmanX/blend_stats/blob/master/blend_stats.py) $\endgroup$
    – CodeManX
    Feb 25 '20 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.