Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Maya script that merges overlapping vertices within each selected mesh, using a user-specified merge threshold.
import pymel.core as pm
# mergeVerts()
# Author: Jocelyn Kim
# Function: Mass merge overlapping vertices on selected mesh(es) under a user-specified threshold
# 'meshes' is a list of all of the meshes in the user's selection
meshes = [x for x in [ thing for thing in pm.selected() if thing.getShape()] if x.getShape().nodeType() == 'mesh']
# UI Layout
win = pm.window (title="Merge Overlapping Vertices", rtf=True)
layout = pm.columnLayout()
threshold_text = pm.text (label='Merge Threshold', parent=layout)
threshold_field = pm.textField (tx='0.001', parent=layout)
btn = pm.button (label='MERGE', parent=layout)
def onButtonPressed (*args):
# for every mesh in the 'meshes' list:
for mesh in meshes:
numVerts = mesh.verts
oldVerts = float(len(numVerts))
# clear selection list before starting
pm.select (clear=True)
# selected vertices in this mesh
for v in numVerts:
pm.select(v, add=True)
# designate new threshold value based on what user specified (defaults to 0.001)
thr = pm.textField (threshold_field, query=True, text=True)
newThreshold = float(thr)
# merge 'em!
pm.polyMergeVertex (d=newThreshold)
newVerts = float(len(mesh.verts))
print ("MERGED for mesh: " + mesh + "~ old vert count: " + str(oldVerts) + ", new vert count: " + str(newVerts))
pm.deleteUI(win)
btn.setCommand (onButtonPressed)
win.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.