Is there any way to use bmesh to remove vertices from vertex groups in edit mode?
It's possible to use it to read this data, clear all groups, and nothing more. Example:
# Get vertex group index vgroup_idx = context.active_object.vertex_groups["Test"].index # Demo verts list demo_keys = [1, 3, 4] # Get verts list verts = np.array(bm.verts) # Check bm.verts.layers.deform.verify() deform = bm.verts.layers.deform.active # Add to group if not, otherwise remove for v in verts: g = v[deform] if v.index in demo_keys: # Set weight by vertex group index g[vgroup_idx] = 1 else: # Remove by doing ??? pass
How to remove it from a group? The deform layer contains BMDeformVerts that can't simply get deleted. The layer itself, a BMLayerCollection, also lacks useful methods like
remove(). It can only be cleared out.
My next thought was to copy the collection contents BMLayerItems, try to remove the undesired weights from the copy somehow then replace the original items with this copy, but besides the risk of messing with other things referencing the original data that's not really possible to copy deforms to somewhere possible unless I duplicate the mesh, as the deform layer type is a singleton. It doesn't work with the
new() method, meaning you don't have somewhere to copy these items to in first place.
Right now I'm resorting to workarounds like storing the vertices and vertex_group selection, selecting the ones I want to remove, using the default
vertex_group_remove_from() operator to remove them then restoring the selections. That's not nice. Ideas?