Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import bpy
class OBJECT_OT_vertex_group_remove_from_inactive(bpy.types.Operator):
"""Remove selected vertices from inactive vertex groups"""
bl_idname = "object.vertex_group_remove_from_inactive"
bl_label = "Remove Vertex From Inactive Vertex Groups"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
obj = context.active_object
return (obj and
obj.type == "MESH" and
obj.vertex_groups)
def execute(self, context):
obj = context.active_object
#removing vertices from vertex groups
#requires object mode
mode = obj.mode
if not mode == "OBJECT":
bpy.ops.object.mode_set(mode="OBJECT")
active = obj.vertex_groups.active_index
selection = [v.index for v in obj.data.vertices if v.select]
for group in obj.vertex_groups:
if group.index == active:
continue
group.remove(selection)
if not mode == "OBJECT":
bpy.ops.object.mode_set(mode=mode)
return {'FINISHED'}
def draw_op(self, layout):
self.layout.column().operator("object.vertex_group_remove_from_inactive")
def register():
bpy.utils.register_class(OBJECT_OT_vertex_group_remove_from_inactive)
bpy.types.VIEW3D_PT_tools_meshweight.append(draw_op)
def unregister():
bpy.types.VIEW3D_PT_tools_meshweight.remove(draw_op)
bpy.utils.unregister_class(OBJECT_OT_vertex_group_remove_from_inactive)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.