Need help to properly select edges in edit mode

In the script I’m writing, I want to get the coordinates of each vertex in each of several edge loops which the script will find (i.e. the edge loops are not manually selected). I am proceeding by getting Python to discover which edges I am interested in and make the selection for me. The script works fine as far as finding a group of single edges which are the starts of the edge loops. It successfully identifies which edges I want to as the beginnings of the edge loops.

The trouble is in trying to select the single edges so I can call bpy.ops.mesh.loop_multi_select(ring=False) to select the rest of the edge loop. The functions I know about require that I toggle into Edit Mode, which introduces issues that I’m not entirely familiar with. Here’s the code snippet I would like to use:

bpy.ops.object.mode_set(mode='EDIT')
        for edge in edgeList:
            bpy.ops.mesh.select_all(action='DESELECT')
            edge.select=True
            bpy.ops.mesh.loop_multi_select(ring=False)
            
bpy.ops.object.mode_set(mode='OBJECT')

Going into this for loop in my test file, edgeList has three parallel edges in it. After running the script, all three edges in the list are selected and any edges I had manually selected remain in the selection. The edge loops are not selected.

So what I see is that select_all is not clearing the selection and loop_multi_select is not adding to the selection.

Is there another way that I can take my list of single edges and select an edge loop from each one?

I wasnt able to use edge.select=True in edit_mode.
So this might work.

bpy.ops.object.mode_set(mode='EDIT')
for edge in edgeList:
     bpy.ops.mesh.select_all(action='DESELECT')
     bpy.ops.object.mode_set(mode='OBJECT')              # +
     edge.select=True
     bpy.ops.object.mode_set(mode='EDIT')                  # +
     bpy.ops.mesh.loop_multi_select(ring=False)
bpy.ops.object.mode_set(mode='OBJECT')

Im not sure how your code will look.

Thanks for the reply. Toggling modes as you suggested still fails to clear the selection. I know there’s something strange about how Blender handles this kind of transition between edit and object mode but I don’t know the specifics well.

In the end I have found a plugin called “Curve Loop” for building a curve out of existing vertices. It has an edge-loop selection method in it. It takes a lot more code that “loop_multi_select” but it works.

Thanks again

It should rather be:

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
for edge in edgeList:
     edge.select=True
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.loop_multi_select(ring=False)

But it’s probably better to use bmesh module for selection making, as you won’t have to switch modes. Note that you should create the edgeList with bmesh as well, and not take standard API edge indices and use them on bm, as they might differ.