Simple command that will merge a vertex to the position of the 'leading'/first vertex?

Currently if I select two vertices and go to Edit Mesh > Merge both vertices will be merged but both of them will always be moved from their position. This is not ideal, I would like only one vertex be moved to the position of the other vertex.

Similar to how with the target weld tool, you can merge two vertices by moving one to the position of another vertex. The reason why I am avoiding to use the target weld tool, is I want to configure a single press hotkey to do this and avoid tool switching and “reset tool” hiccups.

I am open to any suggestions of extensions/scripts that do this, free or not. Or how I can go about to achieve this with a script (I know Mel and Python but very knew to Maya). Thanks!

You could snap second vertex to the first one (or vice versa), and then merge them.

For example (create runtime command for this script, assigning it to some hotkey):

# with pymel
import pymel.core as pmc

vtx_01, vtx_02 = pmc.selected()  # no error checking, assuming selection is correct
vtx_pos = vtx_01.getPosition()
vtx_02.setPosition(vtx_pos)
pmc.polyMergeVertex()


# or with maya.cmds
from maya import cmds

vtx_01, vtx_02 = cmds.ls(sl=True)  # no error checking, assuming selection is correct
vtx_pos = cmds.xform(vtx_01, q=True, ws=True, t=True)
cmds.xform(vtx_02, ws=True, t=vtx_pos)
cmds.polyMergeVertex()
1 Like

Thank you for this, it solves my need as well as provide a good example for how to go about it.