I make a selection of specific edges

indices = [442, 443, 444, 445]
edges = [e for e in bm.edges]
ee0 = []
for vert in edges:
    if vert.index in indices:
        ee0 = ee0 + [vert]

No I would like to get the vertices connected to these edges So I tried

verts = [v for e in ee0 if e.select for v in e.verts]

the result of verts is empty How can I get the vertices connected to an edge?


The reason why your result is empty is because (and im assuming) your not selecting the vertices

Remove the if e.select

verts = [v for e in ee0 for v in e.verts]
| improve this answer | |

Code edit

To the questioner, Please ignore this answer.: it is for others who may come across this question / answer after code to get bmesh elements from their indices, or for those like me who cannot see "not nice" code with out suggesting alteration. Rather than long-commenting added here as an alternate answer.

If we have the indices of vertices can look them up via bm.verts[index], after calling bm.verts.ensure_lookup_table() to ensure the indexing. Similarly for edges and faces. Need only loop over indices.

[bm.edges[i] for i in edge_indices]

Looping over every vertex and checking if v.index == index or worse if v.index in indices, then appending with verts = verts + [v] (suggest verts.append(v)) is both grossly inefficient and s shown, not required.

Use a set for verts in edges to have only one occurrence of each vert. There will be same vert added to list for each connected edge in the list comprehension. Cast it back to a list if need be. list(set(verts))

import bpy
import bmesh

context = bpy.context
ob = context.object
me = ob.data
bm = bmesh.new()

edge_indices = [0, 2, 4]

edges = [bm.edges[i] for i in edge_indices]

all_verts_in_edges = set(v for e in edges for v in e.verts)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.