# How to determine whether my bm.select_history.active is a BMVert, BMFace or a BMEdge?

I am trying to write a conditional statement for my script. If the user has one Active Edge Selected, then the script will run. Otherwise it won't.

I know that if I have an active edge, then bm.select_history_active will print something like , index = ... etc). Otherwise it would print either BMFace or BMVert (correct me if I'm wrong).

So how can I check whether the bm.select_history_active is a BMEdge? Thanks!

Python's isinstance

The method isinstance(ob, type) will return True if the object ob is an instance of type type

Example here

is_edge = isinstance(bm.select_history.active, bmesh.types.BMEdge)


bm.select_history.active actually gives you the object of type of the selected element of the mesh. So actually, type(bm.select_history.active).__name__ will give you the strings 'BMEdge', 'BMVert', 'BMFace' etc. based on the type of selection. You can use this in the condition, which could be something like:

activElem = bm.select_history.active
if (activElem != None and type(activElem).__name__ == 'BMEdge'):
#The logic to process the edge (activElem.index etc.)


There may be a better way to do this. So maybe, you can wait for a while for a better answer :)

• Thanks! I used the other solution in this case. – z01ks Oct 12 '18 at 21:23
• Yes, that one is better. String comparison is not good for checking the object type. – Blender Dadaist Oct 13 '18 at 5:02