Update bmesh selection without leaving edit mode

if, while in Edit mode, I make a selection with e.g :

bmesh.from_edit_mesh(bpy.data.objects['Cube'].data).faces[5].select=True

The selection doesn’t update in the viewport unless I go out of Edit Mode and Back in.

Is there a more “performance-friendly” way to update the viewport?

first of all- if you’re concerned about performance, creating a bmesh the way you have shown is the opposite of what you want to do. constructing and destroying bmesh objects is pretty costly, which is why you want to create it and keep a reference around until you’re sure you don’t need it anymore. Having said that, to answer your question all you need to do is update the edit mesh with the bmesh data. There is one extra step you’ll want to do, so I’ll save you from running into it and then posting again- but you need to flush the selection once it’s been manually changed like this.

bm.select_flush(True)
bm.update_edit_mesh(obj.data)

You should consider looking at some of the bmesh examples that ship with blender- most of this stuff is pretty well covered.

1 Like

thank you. This clarified many things for me.
The bundled bmesh templates are indeed quite informative as well.