Set bmesh active edge

How would I go about setting the active bmesh element in python, specifically the active edge? (And seeing it correctly in the viewport?)

I’ve been searching around and there’s quite a bit on getting it, but I can’t seem to find anything on setting it.

To get the active element, use

To set an active element, use bm.select_history.add(elem)
The last added element will be active, provided that it’s selected.

Optionally, use bm.select_history.validate() after changes to ensure that only selected elements are in select_history.

Update the edit mesh afterwards.

Example that clears the active list and sets an edge (bm.edges[0]) to active:

import bpy
import bmesh

me =
bm = bmesh.from_edit_mesh(me)

edge = bm.edges[0] = True  # select the element before making it active

bm.select_history.clear()  # optionally clear previous elements


Thanks! I got my script working thanks to your help. I suspected it was related to to select_history before, but I was missing a few things.