I want to write an addon that can combine two selections with a logical AND.

For example, the user use via normal gui




Then he calls the addon, the addon gets the current selection, the selection made before, combine them and write the selection back.

My problem is I don't know how I can access these history data via python nor if it's possible. This would be my favorite way of workflow for the addon.

I can extend the addon with a call to store the actual selection, so the user make a similar select, call the addon to store the current selection, make another similar select and call the addon to combine the both selections and write it back.

For this way I need to store a customized boolean at the bmesh faces/edges/vertices data, but I can't figure it out how. If I try to store custom data I run in these error:

bm.faces[0]['and_select'] = False
Traceback (most recent call last):
File "", line 1, in
AttributeError: BMElem[key]: invalid key, must be a BMLayerItem

An example how this must be done would help.

  • $\begingroup$ I don't see a purpose for your intended addon. If you use select similar in the UI, the current selection will be extended. There's really no need to "combine" selections by script. $\endgroup$
    – CodeManX
    Nov 9, 2014 at 15:51
  • $\begingroup$ I don´t want to extend the selection, i want the intersection of two different selections. Such as do a binary AND operation. $\endgroup$
    – rigoletto
    Nov 10, 2014 at 18:11
  • $\begingroup$ I see, check out my addon border deselect outer then. I recommend pink vertex's solution however for your particular problem. $\endgroup$
    – CodeManX
    Nov 10, 2014 at 19:50

1 Answer 1


Don't use the string key. Instead use a direct reference for the layer:

layer = bm.faces.layers.int.new('layer_name')
bm.faces[0][layer] = 0

There is no boolean layer available.

The selection history works only for single verts/edges/faces.

You can use the bmesh operators similar_faces, similar_edges, similar_verts which will return the selection.

Links to the source: bmo_similar.c, bmesh_operators.h


You must log in to answer this question.

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