pythonblenderbpy

Listing vertices per face in python blender (bpy)


In Blender using Python I am trying to list the vertices of each face in a clockwise manner. I can list all faces, I can list all vertices, how do I fix the below script to loop through all faces and while doing so print the vertices (clockwise order)?

import bpy

ob = bpy.context.active_object
me = ob.data
bm = bmesh.from_edit_mesh(me)


for f in bm.faces:
    if f.select:
        print(f.index)
        for v in bm.verts:
            print(v.co)

Solution

  • Each face lists its verts in BMFace.verts. The verts list appears to always be sorted counter-clockwise when looking at the front of the face, so reversed(f.verts) should give what you want.

    for f in bm.faces:
        if f.select:
            print(f.index)
            for v in reversed(f.verts):
                print(v.index, v.co)