Hi,
The script should take the position nearest to the first CV of a given curve and snap that CV to that point on the mesh WHILE keeping the length. The script kind of works, but for whatever reason it doesn’t keep the length, though the attribute becomes turned on and works well if the CVs moved manually
import maya.cmds as cmds
sel = cmds.ls(sl=True)
curves = cmds.listRelatives(sel[1:], s=True)
mesh = cmds.listRelatives(sel[0], s=True)
cpom = cmds.createNode("closestPointOnMesh")
#freeze tr and delete history on the mesh
cmds.makeIdentity(cmds.listRelatives(mesh, p=True), apply=True, t=True, r=True, s=True, n=False, pn=True)
cmds.delete(cmds.listRelatives(mesh, p=True), ch=True)
cmds.connectAttr(mesh[0] + ".outMesh", cpom + ".inMesh")
for crv in curves:
if cmds.objExists(crv + ".lockLength") == False:
cmds.addAttr(crv, ln="lockLength", sn="ll", at="bool", k=True)
cmds.setAttr(crv + ".lockLength", 1)
cmds.connectAttr(crv + ".controlPoints[0]", cpom + ".inPosition")
posX = cmds.getAttr(cpom + ".positionX")
posY = cmds.getAttr(cpom + ".positionY")
posZ = cmds.getAttr(cpom + ".positionZ")
cmds.setAttr(crv + ".controlPoints[0].xValue",posX)
cmds.setAttr(crv + ".controlPoints[0].yValue",posY)
cmds.setAttr(crv + ".controlPoints[0].zValue",posZ)
if cmds.connectionInfo( cpom + ".inPosition", isDestination=True):
cmds.disconnectAttr(crv + ".controlPoints[0]", cpom + ".inPosition")
It looks like a bug, but I’ve checked the script in Maya 2016 and 2017.
I’d appreciate any help.