# best way to select edge to use bmesh.ops.bevel

I would like to bevel some of the edges of my object. I tried this code (works but is not consistent)

bm.edges.ensure_lookup_table()
ebd = [
{'idx': 20, 'profile': 0.5, 'offset': 0.005, 'segments': 10},
]

# first get the edges
for i in range(len(ebd)):
ebd[i]['edge'] = bm.edges[ebd[i]['idx']]

# bevel each edge
for i in range(len(ebd)):
e = ebd[i]['edge']
bev_geom = [e.verts[0], e.verts[1], e]
p = ebd[i]['profile']
o = ebd[i]['offset']
s = ebd[i]['segments']
bmesh.ops.bevel(bm, geom=bev_geom, offset=o, segments=s, profile=p)


I noticed that the index number of the edges changes. So every time I run this code another edge is bevelled. maybe I do something wrong idk. What I did noticed is that the vertex number is the same every time I insert the object. So I was wondering and could not find any on the forum so far that shows me how to select an edge based on 2 vertices. Or how I can select the edges I want and then bevel them so that every time I insert the object the correct edges are bevelled.

Another code I tried is

    indices1 = [3, 15]
vertices = [e for e in bm.verts]
v_edges = []
for vert in vertices:
if vert.index in indices1:
vert.select = True
v_edges = v_edges + [vert]
else:
vert.select = False

bmesh.ops.bevel(bm,
#bev_geom=v_edges,
geom = v_edges,
offset=0.005,
segments=10,
profile=0.5
)


This will obviously select 2 vertices. Can i use these 2 vertices to select the edge between them?

Regards

• You won't be able to do much about the indices changing whenever you add geometry with an operator. – Frederik Steinmetz Dec 27 '19 at 21:04
• @FrederikSteinmetz And it is not possible to select and edge based on 2 vertices? – cexoso Dec 27 '19 at 21:07

I tried thes Lines:

import bmesh
from bpy import context as C

m = C.active_object.data
bm = bmesh.from_edit_mesh(m)

indices = [0,1]
for e in bm.edges:
if e.verts[0].index in indices and e.verts[1].index in indices:
e.select = True
break


The selection doesn't show up in edge select mode, but if you go to vert select, and back to edge, the edge will be correctly displayed as selected. How to continue from there with the operator, I have not tested.

• It only selects the last edge of the object No matter what numbers i give in it does not select any other edge then 0. And I paid attention to the select mode – cexoso Dec 27 '19 at 21:36
• if I insert this into the success line: print("Selecting edge:",i) and i+=1 under the break (less indented) it shows me a different edge selected every time I change the indices. However the visual selection for bmesh does not get updated when you run the script. Because bmesh is destroyed when you leave edit mode, or when the script terminates. You can continue to use your selection in the same script though, try it out, it might just work. – Frederik Steinmetz Dec 27 '19 at 21:59
• Frederik Steinmetz The code you gave works to select 2 vertices (it works) But can it be modified to select multiple pairs? For example 3,15 and 4,16 and so fort – cexoso Dec 27 '19 at 22:41
• if you run a for loop over all desired pairs, I don't see why it wouldn't. .select adds to the current selection, so you can do that as often as you want without losing the previously selected – Frederik Steinmetz Dec 30 '19 at 12:53