I am trying to figure out how I can select multiple objects, and smooth every weight(vertex group) on each object using python, instead of manually doing so for each object. Thanks.


1 Answer 1


That's probably what you need.

import bpy

first_active_obj = bpy.context.view_layer.objects.active
save_mode = first_active_obj.mode

for i in bpy.context.selected_objects:
#    Skip object if vertex group is empty and if object is not a mesh object
    if not i.vertex_groups and i.type != 'MESH': 
#    Set active object and get this object
    active_obj = bpy.context.view_layer.objects.active = i

    save_idx = active_obj.vertex_groups.active_index
    for idx, _ in enumerate(active_obj.vertex_groups):
        active_obj.vertex_groups.active_index = idx
#        Smooth
        bpy.ops.object.vertex_group_smooth(group_select_mode='ALL', factor=0.5, repeat=5, expand=0)

#   Restore active index
    active_obj.vertex_groups.active_index = save_idx

#   Restore active object, and restore mode
bpy.context.view_layer.objects.active = first_active_obj   

You must log in to answer this question.

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