1
$\begingroup$

How can I select these vertices in this weird loops encircled in red using python? In this example I only have 5 vertices excess but it's possible for more or lesser vertices to be junctioned like that.

enter image description here

Or any solution for a filled mesh:

enter image description here

$\endgroup$
6
  • $\begingroup$ How would you characterize such "excess loops" ? Do you have something like "protruding inside/outside" ? Or is it a "path" ? $\endgroup$ Commented Apr 23 at 21:04
  • $\begingroup$ its just flat on the XY plane. and all edges are connected to the same common vertex. I feared it's probably not possible because it seems there is no way to characterize such excess loop. $\endgroup$
    – Megan Love
    Commented Apr 24 at 0:40
  • $\begingroup$ It is possible. 100+ lines of code to write and debug. Recursively traversing the mesh using bmesh and link_edges, detect and delete loops that longer than some amount of verts. $\endgroup$
    – unwave
    Commented Apr 24 at 1:42
  • $\begingroup$ yup that's exactly what i thought. i meant not possible in simple terms though haha. thanks alot for your feedback! but maybe its possible with a few lines to check for loops that are smaller than 10 edges. so basically it will check for junction vertices with 4 edges connected to them and then check only up to 10 linked edges which is longer to traverse. shouldnt be too computationally expensive? $\endgroup$
    – Megan Love
    Commented Apr 24 at 1:59
  • 1
    $\begingroup$ @unwave i found the solution. So initially this shape had faces which i removed. So before I remove those faces, I just extrude it temporarily then i can do select "Interior" faces and it selects these parts. $\endgroup$
    – Megan Love
    Commented Apr 24 at 4:38

1 Answer 1

2
$\begingroup$

Found the solution. Just extrude the mesh and then you can do Select Interior Faces. And then unextrude.

import bpy

obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='OBJECT')
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value":(0, 0, 0.01)})
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_interior_faces()
bpy.ops.mesh.delete(type='FACE')
bpy.ops.object.mode_set(mode='OBJECT')

mesh = obj.data
for face in mesh.polygons:
    normal = obj.matrix_world @ face.normal
    if normal.z > 0:
        face.select = True
        break

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_similar(type='FACE_NORMAL', threshold=0.01)
bpy.ops.mesh.delete(type='VERT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.normals_make_consistent(inside=True)

enter image description here

$\endgroup$

You must log in to answer this question.

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