co for edges and faces with bmesh how to ?

i got this but how so you get the co for each verts per edge or face?

for e in bmesh.edges:
 print('edge =',e,' index =',e.index ,' verts=',e.verts)
 print (' other verts =',e.other_vert)
print ()
print (' Print faces list')
print ()
for f in bmesh.faces:
 print('face=',f,' edges=',f.edges,' index =',f.index,' verts=',f.verts)

thanks for any help

import bpy
import bmesh

object = bpy.context.object
mesh =
bmesh = bmesh.from_mesh(mesh)

for f in bmesh.faces:
    for v in f.verts:

for f in bmesh.faces:
    for e in f.edges:
        for v in e.verts:

first line gives

face= <BMFace(0x0B5E5E00), index=0, totverts=4>

how can you get from this the index and the totverts is this lke a list may be?

also there must be a way to put it into edit mode i guess but how
or use this may be

bpy.ops.object.mode_set(mode = ‘OBJECT’)

bpy.ops.object.mode_set(mode = ‘EDIT’)
but are these bmesh compatible?

on thing here

these commands f.edges: is this in bmesh mode or old API commands?

i mean i saw a module for bmesh verts then edges and faces
but not certain if these can also be use and how


Look at the code below and see if this answers some of your questions, this is using the bmesh module. I’m just learning it too, so please excuse my limited knowledge of this.

This code basically checks if you’re in edit mode, if not changes to it (switches back at the end of the script). Then it prints the numbers of faces, verts and edges. It then goes through and lists how many verts/edges are in each face, and which face has the most.

Pretty basic, but it helped me understand how bmesh is working.

import bpy
import bmesh

my_mode = bpy.context.object.mode # Check if object mode is EDIT, needs to be for bMesh
if bpy.context.object.mode != 'EDIT': 
    bpy.ops.object.mode_set(mode = 'EDIT')

mesh =
bmesh = bmesh.from_mesh(mesh) # Activate bMesh on current mesh

totalverts = len(bmesh.verts)
totaledges = len(bmesh.edges)
totalfaces = len(bmesh.faces)

This object contains:")
print("%s Vertices, %s edges, and %s Faces." % (totalverts, totaledges, totalfaces))

list = []
for face in bmesh.faces:
    faceindex = face .index
    verts = len(face .verts) #Don't need edges because verts == edges on same face
    print("Face %d has: %d verts and edges" % (faceindex, verts))

# Check for the most verts
max_value = max(list)
max_index = list.index(max_value)
%d is the most verts in a face. That face %d" % (max_value, max_index))

# Change the mode back to what it was
if my_mode != 'EDIT':
    bpy.ops.object.mode_set(mode = my_mode)

# Script Footer
FINISHED", "---"*23)
from datetime import datetime

Changing the object mode is compatible with bmesh. What I found when working the with the console the following command needs to be run in ‘EDIT’ mode only, it’ll error in object mode. Running this code will allow you to access the bmesh info.

import bmesh
mesh =
bmesh = bmesh.from_mesh(mesh)

Be warned, if you’re using the console to test commands. If you switch to ‘OBJECT’ mode and back to edit mode, you’ll need to rerun the code above to be able to access bmesh again.

well i guess that everyone is re learning how to make certain things with Bmesh
and probably all the script using verts edges and faces are broken

so i need to learn this basic things cause i have so many script where i make new primitives

i would like to see somethin along this line
i needed i an upload a samll old script for making a primitive that i have using verts edges and faces

but example is very interestin

gives a better idea what canb e done with Bmesh
but i guess till in alpha stage so not certain if this will stay there or be modified again before next release !


how d you determine the number of edge per face ?

right now you got this

Face 0 has: 4 verts and edges

or is it 2 verts / edge

meaning in this case that 4 /2 = 2 edges ?

but this does work for a cube which has one face 4 verts and 4 edges!

if i do this i get bad format !

print(“Face %d has: %d verts and % edges” % (faceindex, verts, verts/2))

get this

Face 0 has: 4 verts and 2 edges


i found this example

list_ = [ [v.index for v in f.verts] for f in bmesh.faces if and f.is_valid]

but have to rewrite this to better understand how it works!

be back with a more elaborate example and easier to understand what’s happening inside the loops


here is another one i’m not certain
on this page

class bmesh.types.BMFace

from this

for f in bmesh.faces:

print ()

got this

class bmesh.types.BMFace

face= <BMFace(0x0B4DD268), index=0, totverts=4> cacl_area()= -3.999999523162842
face= <BMFace(0x0B4DD268), index=0, totverts=4> calc_center_bounds= <Vector (-0
0000, 0.0000, -1.0000)>
face= <BMFace(0x0B4DD268), index=0, totverts=4> calc_center_median= <Vector (0.
000, 0.0000, -1.0000)>

what is the difference from center bound and center median ?

and do you get the number cause here it is like a phrase or text fields

like getting the center bound = vector = <Vector (-0
0000, 0.0000, -1.0000)>


From what I can tell, bMesh creates a list of all the faces in an object. You can then go through that list that contains the faces, and find out which edge/vert indexes are within that face.

import bpy, bmesh

bpy.ops.object.mode_set(mode = 'EDIT')
mesh =
bmesh = bmesh.from_mesh(mesh)

def myedges(face_index):
    face = bmesh.faces[face_index].edges
    print("Face #%d has:" % face_index)
    for edge in face:
        print("edge index #%d" % edge.index)

is the same as

This is what I’m figuring out so far

On the example, when I printed the edges and verts. That number will always be the same, a face with four verts will always have four edges as well. For simplicity I only calculated the number of verts, and just assumed that there were the same number of edges. " 4 verts and edges == 4 verts and 4 edges"

Interesting learning this stuff…

any example for these ones

class bmesh.types.BMIter
Internal BMesh type for looping over verts/faces/edges, used for iterating over BMElemSeq types.
class bmesh.types.BMLoop

seems much more powerfull then the older version
and more fun i guess
you can do lot more
but need to practice

i got to find one of my old script to make a primitive and try to convert it to bmesh!

got a problem when copying from web page to text ediitor

if ther are any un8 character like end of line
blender freeze

is there anyway to get rid of these un8 characters
or to detect them in text editor ?


did a test here with these

for f in bmesh.faces:

print ()

and got these

class bmesh.types.BMFace
face= <BMFace(0x0B63AD40), index=0, totverts=4>
cacl_area()= -3.999999523162842
calc_center_bounds= <Vector (-0.0000, 0.0000, -1.0
calc_center_median= <Vector (0.0000, 0.0000, -1.00
edges= <BMElemSeq object at 0x0ADE0530>
index= 0
loops= <BMElemSeq object at 0x0ADE0530>
normal= <Vector (0.0000, 0.0000, -1.0000)>
smooth= False
verts= <BMElemSeq object at 0x0ADE0530>

not certain what the loops is doing here and samethign with this verts
it gives like an address instead of data !