Foreach_get for selected vertex indices?

These Blender design choices are making the life of an add-on dev unnecessarily complicated.

  • bmesh doesn’t have a list of which components are selected.
  • bmesh doesn’t have foreach methods to quickly build such a list.
  • object.data.vertices has both, but it doesn’t update when the selection changes in Edit mode.
  • bmesh.select_history has a list but doesn’t include box/lasso/circle/other selected vertices.

The end result is that add-on devs have to…

  • loop over the entire bmesh with a list comprehension (slow on dense meshes)
  • or do hacks like mode switching or ob.update_from_editmode() to update the object.data (extremely expensive for dense meshes which defeats the purpose of wanting to use foreach with numpy because the slow list comprehension will be faster)
  • or re-implement and replace Blender functions and tools in their own python scripts and manually handle all tracking themselves (if you’re crazy and/or a masochist).

Is there really no faster way to get the selected vertices from a bmesh than to loop the entire mesh with a list comprehension?

4 Likes