So I wrote this way back in 2015 and I had a lot of people ask about it coming from a YouTube video. This is the old version of the script, I’ll rewrite it to be a bit more streamlined some time soon.

``````def copy_vertex_weights():

#TODO: make a ui for this so whoever's using it can set the minimum distance between verts that need
#      to share vertex weights

# Any vertices closer together than this distance will share the same vertex weight
copyDistance = 0.7

# Make sure that the selection is converted to vertices
cmds.select(cmds.polyListComponentConversion(cmds.ls(selection = True, flatten = True), toVertex = True))
selection = cmds.ls(selection = True, flatten = True)

# Two lists to store the vertices of both the head and the body edges
first_object_vertices = []
second_object_vertices = []

for i in xrange(0, len(selection) / 2):
vertex = Vertex(selection[i])
first_object_vertices.append(vertex)

for i in xrange(len(selection) / 2, len(selection)):
vertex = Vertex(selection[i])
second_object_vertices.append(vertex)

# Iterate over both lists to find vertices that are close enough together to share weights
for first_vertex in first_object_vertices:
for second_vertex in second_object_vertices:
if get_distance_between_vertices(first_vertex, second_vertex) < copyDistance:
cmds.select(first_vertex.name)
mel.eval('artAttrSkinWeightCopy;')
cmds.select(second_vertex.name)
mel.eval('artAttrSkinWeightPaste;')

def get_distance_between_vertices(vertexA, vertexB):
# distance between 2 points in 3D is
#
# squareRoot[ <(point1.x - point2.x)^2> + <(point1.y - point2.y)^2> + <(point1.z - point2.z)^2> ]
#

vertexAx, vertexAy, vertexAz = vertexA.get_world_position()
vertexBx, vertexBy, vertexBz = vertexB.get_world_position()

distance = ((vertexAx - vertexBx)  ** 2 + (vertexAy - vertexBy) ** 2 + (vertexAz - vertexBz) ** 2) ** 0.5
return distance

class Vertex:
"""
Tiny little class to treat the vertices as objects
"""

def __init__(self, name):
self.name = name

def get_object_name(self):
return self.name.split('.')

def get_world_position(self):
return cmds.pointPosition(self.name, world = True)

def print_debug_info(self):
print "Name: " + self.name
print "Object Name: " + self.get_object_name()
print "World Position: " + str(self.get_world_position())

copy_vertex_weights()

``````