# When I subdivide a face, how do I get each face from the result in Python?

For example, if I subdivided a square face so there were now 4 faces, how I do iterate through those 4 faces in a Blender add-on?

• Could you elaborate on the question. Do you mean : you want to map the newly created faces on the old face, which was subdivided? If yes, I don't think that kind of history would be maintained in any of the built-in objects. If you simply want to iterate through the faces, you can do that through bmesh.faces iterator. Here, you won't get the face that was subdivided but the new 4 faces that were the result of the subdivision. – Blender Dadaist Oct 11 '18 at 14:56
• @BlenderDadaist I would like the second option; I simply want to iterate through the new faces. – Maria Oct 11 '18 at 15:09

Here is the code to iterate through the faces of the selected object:

import bmesh
import bpy

obj = bpy.context.object
me = obj.data

if me.is_editmode:
bm = bmesh.from_edit_mesh(me)
else:
bm = bmesh.new()
bm.from_mesh(me)

for face in bm.faces:
print(face.index)


Bmesh approach

Using the bmesh operator bmesh.ops.subdivide_edges(..) with cuts = 1 and use_grid_fill = True will produce the result of subdividing a quad face into four.

Test script, run in edit mode, subdivides face 0, prints the four newly added faces.

import bpy
import bmesh
context = bpy.context
ob = context.edit_object
me = ob.data

bm = bmesh.from_edit_mesh(me)

face = bm.faces[0]
ret = bmesh.ops.subdivide_edges(bm, edges=face.edges[:], cuts=1)
for f in ret['geom']:
# new geometry
if isinstance(f, bmesh.types.BMFace):
print(f)