How to remove selected vertexes from all vertex group, except locked

How to remove selected vertexes from all vertex group, except locked? Unfortunately, “Remove from all groups” removes the selected vertices from the blocked ones as well. All the methods of removing vertices from vertex groups that I have found are removed either from only one selected group, or from all at once.

There is an option to delete all vertex groups that are unlocked from a selected object.

I need to remove vertices from unlocked vertex groups, but not the groups themselves.

To my knowledge, you cannot clear nor move a vertex group column order.

What you can do however, is delete all unlocked vertex groups, then recreate them from scratch, using their saved names as the new vertex group name(s). Unfortunately, as I mentioned above, there doesn’t seem to be a way to set a vertex group index column, meaning they’ll be out of order if you run the code, however, that might be acceptable, not sure.

import bpy


for g in bpy.context.object.vertex_groups:
    if g.lock_weight == False:
    n =
    n.lock_weight = True

The script also requires the locking of the new vertex groups, otherwise Blender will infinitely create and delete vertex groups in an endless loop.