I’m having trouble digging up a good example for setting vertex group values on a bmesh. Basically, I want to write a script that creates a bmesh from the selected object, creates a new vertex group on it if one doesn’t already exist and then writes data values for each value. Is there a way to do this?
it’s pretty straightforward using bmesh vertex data layers. basic example:
bm = bmesh.from_edit_mesh(obj.data)
deform_layer = bm.verts.layers.deform.verify()
for vert in bm.verts:
weight_value = 0.75
vert[deform_layer][group_index] = weight_value
bmesh.update_edit_mesh(obj.data)
where group_index is the index of the vertex group you’re trying to modify. If you need to create a vertex group also, it’s also pretty simple:
vgroup = obj.vertex_groups.new(name="WhateverName")
group_index = vgroup.index
1 Like