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)
import bpy
import bmesh
object = bpy.context.object
mesh = object.data
bmesh = bmesh.from_mesh(mesh)
for f in bmesh.faces:
for v in f.verts:
print(v.co)
for f in bmesh.faces:
print(f)
for e in f.edges:
print(e)
for v in e.verts:
print(v,v.co)
Ricky,
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 = bpy.context.object.data
bmesh = bmesh.from_mesh(mesh) # Activate bMesh on current mesh
totalverts = len(bmesh.verts)
totaledges = len(bmesh.edges)
totalfaces = len(bmesh.faces)
print("
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
list.append(verts)
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)
print("
%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
print("
FINISHED", "---"*23)
from datetime import datetime
print(datetime.now())
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.
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 !
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 = bpy.context.object.data
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)
print("
")
myedges(0)
myedges(2)
bmesh.faces[0].edges[1]
is the same as bmesh.edges[1]
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"