I've written an operator to check all vertices' bone weights and change them according to some rules, in Edit Mode. If I check the new bone weights while still in Edit Mode, they have the correct value. If I switch to Object Mode and then back to Edit Mode, however, all the new bone weights are lost and the vertices have the old ones. Why is this happening?

This is an example of what I'm doing to change the bone weights:

for vertex in context.edit_object.data.vertices:
    for gr in vertex.groups:
        gr.weight = 1

EDIT: Doing context.edit_object.data.update() after chanigng the bone weights doesn't fix the problem.

Thanks in advance!


1 Answer 1


One way is to set up a dictionary with key groupname and a list of vertex indices and add them in object mode using vertex_group.add(..)

import bpy
context = bpy.context
ob = context.object

dic = {}
for g in ob.vertex_groups:
    dic[g.name] = []

for vertex in ob.data.vertices:
    for gr in vertex.groups:

# has to be in object mode for vertex_group.add
w = 1.0
for vgname, verts in dic.items():
    ob.vertex_groups[vgname].add(verts, w, 'REPLACE')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .