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?
Asked
Active
Viewed 731 times
1
-
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
2 Answers
1
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)
batFINGER
- 84,216
- 10
- 108
- 233
0
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)
Blender Dadaist
- 1,559
- 8
- 15