Face specific operations

The goal is to separate some faces from a mesh according to the vertex groups.

First of all the operation should apply to a bunch of faces. So when i have nothing selected and apply the code for the selection, i can see that the faces are selected but they are kind of greyed out, so when the code tries to apply the bpy.ops.mesh.separate() it spawns that nothing is selected…

Now when i am toggling the edit mode, i see the selection updated…

Am i missing something? Is there any other way to select the faces?

Currently i am using bmesh:

bm=bmesh.from_edit_mesh(context.object.data)

and assuming that i have all the vertices of the vertex group in a list verts_0=[]

i do it like:


for f in bm.faces:
 for v in f.verts:
   if v in verts_0:
      f.select=True
      break

Quoting theBmesh docs:

When modeling in blender there are certain assumptions made about the state of the mesh.

  • hidden geometry isn’t selected.
  • when an edge is selected, its vertices are selected too.
  • when a face is selected, its edges and vertices are selected.
  • duplicate edges / faces don’t exist.
  • faces have at least 3 vertices.

To give developers flexibility these conventions are not enforced, however tools must leave the mesh in a valid state else other tools may behave incorrectly.

Any errors that arise from not following these conventions is considered a bug in the script, not a bug in blender.

In other words, the behaviour you expect from using Blender does not apply in scripting. Try selecting the vertices (and edges?) as well.

instead of
f.select = True

try
f.select_set(True)

Now when i am toggling the edit mode, i see the selection updated…

You should call
bmesh.update_edit_mesh(context.object.data)
to flush changes and to see the current state of the mesh in viewport.