0
$\begingroup$

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!

$\endgroup$

2 Answers 2

1
$\begingroup$

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)
$\endgroup$
0
1
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Thanks! I used the other solution in this case. $\endgroup$ Commented Oct 12, 2018 at 21:23
  • $\begingroup$ Yes, that one is better. String comparison is not good for checking the object type. $\endgroup$ Commented Oct 13, 2018 at 5:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .