1
$\begingroup$

I am figuring out a way to check if vertex group is empty or not. if it contains at least 1 vertex or totally empty.

I am trying to make if condition to check for empty vertex group and delete the vertex group if it's empty

can I do this with vertex group data or should i use functions from bmesh

$\endgroup$
2
$\begingroup$

Using list comprehension

similar to that used in this answer

Because we are only interested in empty group will use python any to move on quickly when a non empty group is found.

import bpy
ob = bpy.context.object
me = ob.data
for vg in ob.vertex_groups:
    mtvg = not any(vg.index in [g.group for g in v.groups] for v in me.vertices)
    print(vg.name, mtvg)

Then if vertex group vg is empty can remove with

ob.vertex_groups.remove(vg)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.