1
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Commented Oct 11, 2018 at 14:56
  • $\begingroup$ @BlenderDadaist I would like the second option; I simply want to iterate through the new faces. $\endgroup$
    – Maria
    Commented Oct 11, 2018 at 15:09

2 Answers 2

0
$\begingroup$

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:
    #Your logic here
    print(face.index)
$\endgroup$
1
$\begingroup$

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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .