4
$\begingroup$

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.

$\endgroup$

1 Answer 1

9
$\begingroup$

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.vertices)
len(me.edges)
len(me.polygons) # faces

Vertex count of a single face:

len(me.polygons[0].vertices)
$\endgroup$
6
  • $\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
    Commented Jul 12, 2014 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
    Commented Jul 12, 2014 at 20:24
  • $\begingroup$ So can I use the same code to find vertices and faces in like tetrahedron? $\endgroup$
    – user5184
    Commented Jul 12, 2014 at 21:27
  • $\begingroup$ what about find all vertices count in the scene? $\endgroup$
    – four two
    Commented Feb 24, 2020 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
    Commented Feb 25, 2020 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .