Using Python to select Inner loop in my mesh is producing unexpected results. Any suggestions? Blender 2.8

I have many 2d meshes that have many edge loops created with the Inset Straight Skeleton Tool and I'm hoping I can clean up some of the unwanted edge loops in an automated way.

So far I've found:

import bpy
import bmesh
context = bpy.context

obj = context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
bm.select_mode |= {'EDGE'}
for e in bm.edges:
e.select = e.is_boundary
bm.select_flush_mode()
me.update()


Or potentially more simply done with bpy.ops.mesh.region_to_loop()

This will let me select the outer edge loop, but I am struggling to find anything that will let me select the innermost edge loop properly. If I can select both of these then I can just perform an inverse selection and delete the unwanted edges inbetween them. Does anyone know why my inner loop selection would not be selecting the innermost loop?

Using Select Loop Inner-Region from the Select menu produces an unexpexted result. (or bpy.ops.mesh.loop_to_region() in Python)

Is this what you want to select?

for v in bm.verts:
v.select = not v.is_boundary

• Unfortunately not, as that just selects everything but the boundary. I want to select both edge loops shown in the first image. The first can be done by using is_boundary, but the inner most loop (the one on the opposite side) looks like it needs some more convoluted code to acheive. Using 'not v.is_boundary' just selects everything except for the boundary loop. – James Oct 5 '19 at 21:42
• The image isn't clear enough. – Quantic_Solver Oct 6 '19 at 7:02
• Added extra image. – James Oct 6 '19 at 10:26

You are using multiple selection modes.

Change line 8 of your code to prevent vertex selection

bm.select_mode = {'EDGE'}

Note the use of = instead of |= to force edge selection only.

Without a blend file to test on I'm not sure of the gotchas but the following is a quick and dirty way to do what I believe you are trying to achieve:

import bpy

bpy.ops.mesh.loop_multi_select()
bpy.ops.mesh.loop_to_region()
bpy.ops.mesh.select_less()

• Hi Merlin, I hadn't realized that |= selected vertex as well as edge. Thankyou. – James Oct 8 '19 at 19:54
• No problem, yeah the |= is pronounced "or equals" sets a flag (in this case 'EDGE') in addition to the current flag set. If this answers your question please set as accepted answer so others can see that this has been resolved. – Moog Oct 8 '19 at 20:01
• Hi Merlin, unfortunately it doesn't help me solve selecting the selection of the very last loop. What you see in the image is the result of using the Inset Straight Skeleton. It's the only tool I can find that creates an inset for my shapes without creating edge overlaps. Unfortunately, the way it avoids overlapping edges is to create another edge ring all the way around everytime a overlap is going to occur/edge collision. All I want is the outer most and inner most edge loop. Everything in between them I want to get rid of. – James Oct 8 '19 at 20:22
• I 'm currently looking at using bmesh, doing a vert count for the whole mesh, select vert 0 and 1, select edge loop, selecting the very last vert and one before then select edge loop, invert selection and deleting. I know vert 0 and 1 will be on the outer ring at the start and I know the last two vert ID's will be on the very inner edge loop. Unfortunately I'm running into issues when selecting verts with bmesh, then switching to bpy. It seems like the elements of bmesh I want to use require object mode and the bpy ones need edit mode. Switching within for loops seems to be causing me trouble. – James Oct 8 '19 at 20:28
• Ah okay, I think I see what you're getting at, I've updated my answer but an example blend file would be invaluable to nail this issue – Moog Oct 8 '19 at 21:21