# Locate and assign weights to vertices with no weights in a Mesh

I have a mesh and I make automatic weighting. But the problem is that some vertices are not assigned to have any weight, and I can't locate these vertices due to the complexity of my mesh. I'm asking if there is a way where I can locate and assign auto-weights to these vertices? If anyone could please advise.

This answer has some relevant code for finding vertices without weights: Checking if a vertex belongs to a vertex group in python

Based on that you might try something along these lines:

import bpy

auto_weights = 0.1
ob = bpy.data.objects['NameOfYourMeshObject']

for v in ob.data.vertices:                     # for each vertex
for g in v.groups:                         # for each vertex group in the mesh
if g.weight == 0.0:                    # if the vertex is unweighted
g.weight = auto_weight             # then set the weight


This probably isn't quite right, you might need another test to check if a vertex is in a vertex group or not, depending on the details of your problem.

I had this problem and came here so hopefully my script will save someone some time and headache looking through the blender API

# Usage: with a mesh selected, run the script. It will add a new
# vertex group to the mesh called 'ProblemVertices'
# The script will add any vertices with a total weight != 1.0
# to the 'ProblemVertices' group.

import bpy

print("Start script")

me = bpy.context.object.data                # the selected mesh
grps = bpy.context.object.vertex_groups     # all vertex groups in the mesh
grps.new(name="ProblemVertices")            # add a vertex group to the mesh
myvertexgroup = grps[-1]                    # the last vertex group in the mesh - our new group

# optional part which when uncommented deletes vertices
# from groups where the vertex has weight 0 for that group.
#for vertex in me.vertices:
#    for grpelement in vertex.groups:                        # for each vertex group element in the mesh
#       if grpelement.weight == 0.0:                        # if the vertex is unweighted
#           grps[grpelement.group].remove([vertex.index])   #remove it from that group
#           print("Removed Vertex from group")
#       if len(vertex.groups) == 0:                            # if the vertex is not a member of any groups