Connect to vertices with new edge

Hi Everyone,

in addition you will find a sketch of what i try to do.
I would like to connect two existing vertices from a mesh with a new edge.
The vertex_index in this case would be [0] and [2]

In Blender i would switch to editmode and press “f”, with the two vertices selected.

How could i achive this in Python? Of course I could switch to edit-mode, select the to vertices and do:
bpy.ops.mesh.edge_face_add()

But that seems a little bit messy to me.

Is there a more professional way to do so?

Best,
Chris

Attachments


Standard API:

# mesh must not be in edit-mode!
bpy.ops.object.mode_set(mode='OBJECT')

me.edges.add(1)
edge = me.edges[-1]
edge.vertices = (0, 2)

Bmesh module:

bm.verts.ensure_lookup_table()
v1, v2 = bm.verts[0], bm.verts[2]
bm.edges.new((v1, v2))

Hi CoDEmanX,

thank you very much for the fast answer! This is what i was looking for.

Best,
Chris

One addition for all others: After connecting the vertices, the mesh needs to be updated

me.update()