bmesh edges for face




print ('List of faces ')
print ()
totalverts = len(bme.verts)
totaledges = len(bme.edges)
totalfaces = len(bme.faces)
print ()
print("
This object contains:")
print("%s Vertices, %s edges, and %s Faces." % (totalverts, totaledges, totalfaces))
print ()
for face in bme.faces:
faceindex = face.index
verts = len(face.verts) # Don't need edges because verts == edges on same face
list.append(verts)
print("Face %d has: %d verts and %d edges" % (faceindex, verts, verts/2))
if verts==4: # quad face but coplanar ?
print('Quad face index=',faceindex)
for e1 in face.edges:
# print('edge=',e1)
for v1 in e1.verts:
print('vert=',v1,'c0=',v1.co)
print ()
print (' End of face quad')



but this does not show the right number of edges

how can it be corrected

thanks

what is the supposed number of edges and what does it tell you?

this was working last year

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

but now it does not really work anymore!

let me find the script to run it be back later

thanks

try:
print(“Face %d has: %d verts and %d edges” % ( faceindex, verts, len(face.edges) ))

I doubt it did, it probably just seemed like it was working, but actually failed for corner cases. Consider a mesh with loose verts: if you got two unconnected vertices, your calculation would claim that there’s 2/2 = 1 edge. verts/2 is obviously wrong. If you had 3 loose verts, it would even give you a bad type (3/2 = 1.5 -> float). And 3 connected vertices can make up two edges, or 3 + a face.

as i remember this was working last year

try it on a simple cube

this should give the verts for one simple edge only on a face
which mean only 2 verts first one and second one!



 
import bpy
import bmesh
 
 
# http://www.blender.org/documentation/blender_python_api_2_62_0/bmesh.types.html#bmesh.types.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')
 
 
 
 
 
object = bpy.context.object.data
bm = bmesh.new()     # create an empty BMesh
bm.from_mesh(object)    # fill it in from a Mesh
 
 
totalverts = len(bm.verts)
totaledges = len(bm.edges)
totalfaces = len(bm.faces)
 
print("
This object contains:")
print("%s Vertices, %s edges, and %s Faces." % (totalverts, totaledges, totalfaces))
 
 
 
list = []
 
 
print ()
print ('List of faces verts edges using  % (faceindex, verts, verts/2)')
print ()
 
for face in bm.faces:
 
 faceindex = face.index
 verts = len(face.verts)    # Don't need edges because verts == edges on same face
 list.append(verts)
 print("Face %d has: %d verts and %d edges" % (faceindex, verts, verts/2))
 
print ()
 
           # Check for the most verts
max_value = max(list)
max_index = list.index(max_value)
print("
%d is the most verts in a face. That face %d" % (max_value, max_index))
print ()
 
 
 
 
print ()
print ('List of faces verts edges ')
print ()
 
 
 
for face in bm.faces:
 
 faceindex = face.index
 verts = len(face.verts)    # Don't need edges because verts == edges on same face
 list.append(verts)
# print("Face %d has: %d verts and %d edges" % (faceindex, verts, verts/2))
 print("Face %d has: %d verts and %d edges" % ( faceindex, verts, len(face.edges) )) 
 
print ()
 
           # Check for the most verts
max_value = max(list)
max_index = list.index(max_value)
print("
%d is the most verts in a face. That face %d" % (max_value, max_index))
print ()
 
 


the new line seems to be ok now

this was one of the first example i got for Bmesh
but anyway now seem to work again which is good

thanks