List selected vertices in multi-object editing

Hi,
I’ve searched everywhere I know, I couldn’t find how to list all the selected components (be it vertices, edges or faces) while in multi-object editing. All my attempts could only list those of the active object.

Note: going in and out of edit mode for each selected object is not an option for me, as it would be too slow.

bms = {}
for o in context.objects_in_mode:
    if not hasattr(o, "data"):
        continue
    bm[o] = bmesh.from_edit_object(o.data)

# then later on
for o in bms:
    for v in bms[o].verts:
        print(f"{o.name} - {v.index}, {v.co}")

you don’t have to store the bmesh objects in a dictionary, you could do whatever you need to do in that first loop- but I find that it’s convenient to do it this way, especially if you’re writing a modal operator.

Thanks.
I can’t get a printed list though. If I’m in edit mode, I get an
AttributeError: module 'bmesh' has no attribute 'from_edit_object'

and in object mode I get nothing at all.

from_edit_object returns no search result in the API

Sorry, should be from_edit_mesh, I did that from memory on my phone :slight_smile:

Thank you!

I made some changes and the following snippet makes a dictionary where keys are the object paths and their respective values are the indices of their selected vertices:

import bpy
import bmesh

dic_v = {}
for o in bpy.context.objects_in_mode:
    dic_v.update( {o : []} )
    bm = bmesh.from_edit_mesh(o.data)
    for v in bm.verts:
        if v.select:
            dic_v[o].append(v.index)

print(dic_v)