Python: Access mesh selection history data I want to write an addon that can combine two selections with a logical AND.

For example, the user use via normal gui

bpy.ops.mesh.select_similar(type='LENGTH')


and

bpy.ops.mesh.select_similar(type='DIR').


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.
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