I have empty squares (those with exactly 4 edges only) in my 2D mesh and I need to fill them with faces via python but I don't know how to automatically select these edges. Is it possible to select all of these regions marked in orange via python?
This is what I tried. I selected all edges that have linked exactly only 1 face. Unfortunately it selects the boundary edges as well so I tried doing an and not edge.is_boundary but then nothing gets selected since the small squares inside are apparently also boundary edges.
import bpy
import bmesh
obj = bpy.context.active_object
mesh = obj.data
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bm = bmesh.from_edit_mesh(mesh)
for edge in bm.edges:
edge.select = False
edges_to_select = []
for edge in bm.edges:
if len(edge.link_faces) == 1: #and not edge.is_boundary:
edges_to_select.append(edge)
for edge in edges_to_select:
edge.select = True
bmesh.update_edit_mesh(mesh)
Here's another try where I almost got the result:
import bpy
import bmesh
obj = bpy.context.active_object
mesh = obj.data
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bm = bmesh.from_edit_mesh(mesh)
for edge in bm.edges:
edge.select = False
edges_to_select = []
for edge in bm.edges:
if len(edge.link_faces) == 1:
vertices_with_four_edges = all(len(v.link_edges) == 4 for v in edge.verts)
if vertices_with_four_edges:
edges_to_select.append(edge)
for edge in edges_to_select:
edge.select = True
bmesh.update_edit_mesh(mesh)




