0

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!

Peeter Maimik
  • 421
  • 2
  • 9

2 Answers2

1

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 :)

Blender Dadaist
  • 1,559
  • 8
  • 15
1

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)
batFINGER
  • 84,216
  • 10
  • 108
  • 233