4

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.

CodeManX
  • 29,298
  • 3
  • 89
  • 128
user5184
  • 41
  • 1
  • 1
  • 2

1 Answers1

9

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)
CodeManX
  • 29,298
  • 3
  • 89
  • 128
  • 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 – user5184 Jul 12 '14 at 19:42
  • 1
    You need to run it inside of Blender, which comes with its own Python 3.x and the bpy module. – CodeManX Jul 12 '14 at 20:24
  • So can I use the same code to find vertices and faces in like tetrahedron? – user5184 Jul 12 '14 at 21:27
  • what about find all vertices count in the scene? – four two Feb 24 '20 at 16:40
  • 1
    @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: https://github.com/CoDEmanX/blend_stats/blob/master/blend_stats.py) – CodeManX Feb 25 '20 at 15:30
  • @CodeManX could you check my post here tell me what could i do with my verts count.. I understand what you say about mode dependent and the modifiers and such and that's a great pointer, didn't think about that, will definitely would like to use just the scene.statistics i think.. https://blender.stackexchange.com/questions/167862/create-n-panel-button?noredirect=1#comment283331_167862 – four two Feb 25 '20 at 17:28