## **Description**
The “Vertex Group Cleaner” script removes empty vertex groups from selected mesh objects in a Blender scene. An empty vertex group is defined as a vertex group that has no vertices assigned to it. This script helps declutter the vertex groups list and improves the organization of mesh objects.
## How to Use
1. Open Blender and load the scene containing the mesh objects you want to process.
2. In the 3D Viewport, select the mesh objects with vertex groups that you want to clean up.
3. Open the Scripting workspace or Text Editor in Blender and create a new text file.
4. Copy and paste the “Vertex Group Cleaner” script into the text file.
5. Click the “Run Script” button to execute the script.
6. The script will process the selected mesh objects and remove any empty vertex groups.
## Source
```python
import bpy
def is_vertex_group_empty(obj, group_index):
for v in obj.data.vertices:
for g in v.groups:
if g.group == group_index:
return False
return True
# Iterate over all selected objects
for obj in bpy.context.selected_objects:
# Check if the object is a mesh
if obj.type == 'MESH':
# Check the object's vertex groups and delete any vertex group that has no assigned vertices
i = 0
while i < len(obj.vertex_groups):
if is_vertex_group_empty(obj, i):
obj.vertex_groups.remove(obj.vertex_groups[i])
else:
i += 1
```