## Script Description This Blender script manages vertex groups for selected mesh objects by creating new vertex groups with names derived from the mesh’s name and prefixed with “# “. Each vertex group includes all vertices in the mesh, assigned with the maximum weight value (1.0). The script also performs a cleanup by deleting any existing vertex groups that have names prefixed with “#” but correspond to different selected meshes. ## How to Use 1. Open Blender and navigate to the Scripting workspace. 2. Create a new script in the Script Editor. 3. Copy and paste the script code into the Script Editor. 4. Select one or more mesh objects in the 3D Viewport. 5. Click the “Run Script” button in the Script Editor to execute the script. 6. The script will create or update vertex groups for the selected meshes, assign all vertices to the vertex groups with the “#” prefix, and perform the cleanup as described. ## Source ```python import bpy # Get selected objects selected_objects = bpy.context.selected_objects # Raise exception if no objects are selected if len(selected_objects) == 0: raise Exception("No objects selected.") # Build a set of vertex group names that correspond to the selected meshes vertex_group_names = {f"# {obj.name}" for obj in selected_objects if obj.type == 'MESH'} # Iterate over selected objects for obj in selected_objects: # Check if the selected object is a mesh if obj.type != 'MESH': # Skip non-mesh objects continue # Get mesh name and corresponding vertex group name mesh_name = obj.name vertex_group_name = f"# {mesh_name}" # Delete vertex groups that match the names in the set for group in obj.vertex_groups: if group.name in vertex_group_names: obj.vertex_groups.remove(group) # Create the vertex group for the current mesh vertex_group = obj.vertex_groups.new(name=vertex_group_name) # Get all vertex indices in the mesh vertex_indices = [v.index for v in obj.data.vertices] # Assign all vertices to the vertex group with maximum weight (1.0) vertex_group.add(vertex_indices, 1.0, 'ADD') # Set the active object to the last selected mesh (optional) bpy.context.view_layer.objects.active = obj ```