1
$\begingroup$

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?

Example of outer and inner edge loops I want to auto select enter image description here

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

Select Inner-Region

$\endgroup$

2 Answers 2

0
$\begingroup$

Is this what you want to select?

for v in bm.verts:
    v.select = not v.is_boundary
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – James
    Commented Oct 5, 2019 at 21:42
  • $\begingroup$ The image isn't clear enough. $\endgroup$ Commented Oct 6, 2019 at 7:02
  • $\begingroup$ Added extra image. $\endgroup$
    – James
    Commented Oct 6, 2019 at 10:26
0
$\begingroup$

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()
$\endgroup$
6
  • $\begingroup$ Hi Merlin, I hadn't realized that |= selected vertex as well as edge. Thankyou. $\endgroup$
    – James
    Commented Oct 8, 2019 at 19:54
  • 1
    $\begingroup$ 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. $\endgroup$
    – Moog
    Commented Oct 8, 2019 at 20:01
  • $\begingroup$ 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. $\endgroup$
    – James
    Commented Oct 8, 2019 at 20:22
  • $\begingroup$ 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. $\endgroup$
    – James
    Commented Oct 8, 2019 at 20:28
  • $\begingroup$ 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 $\endgroup$
    – Moog
    Commented Oct 8, 2019 at 21:21

You must log in to answer this question.

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