String literals in Python are formed using only " or ' for one line strings. For multiline strings you can use: """....
So, to solve the syntax error just change:
pci = cmds.createNode(""pointOnCurveInfo" , n = name )
To:
pci = cmds.createNode("pointOnCurveInfo" , n = name )
The second error is raised because the function getUParam is not defined at that moment, so you must define this getUParam function before using it, like this:
from maya import cmds , OpenMaya
def getUParam( pnt = [], crv = None):
point = OpenMaya.MPoint(pnt[0],pnt[1],pnt[2])
curveFn = OpenMaya.MFnNurbsCurve(getDagPath(crv))
paramUtill=OpenMaya.MScriptUtil()
paramPtr=paramUtill.asDoublePtr()
isOnCurve = curveFn.isPointOnCurve(point)
if isOnCurve == True:
curveFn.getParamAtPoint(point , paramPtr,0.001,OpenMaya.MSpace.kObject )
else :
point = curveFn.closestPoint(point,paramPtr,0.001,OpenMaya.MSpace.kObject)
curveFn.getParamAtPoint(point , paramPtr,0.001,OpenMaya.MSpace.kObject )
param = paramUtill.getDouble(paramPtr)
return param
def getDagPath( objectName):
if isinstance(objectName, list)==True:
oNodeList=[]
for o in objectName:
selectionList = OpenMaya.MSelectionList()
selectionList.add(o)
oNode = OpenMaya.MDagPath()
selectionList.getDagPath(0, oNode)
oNodeList.append(oNode)
return oNodeList
else:
selectionList = OpenMaya.MSelectionList()
selectionList.add(objectName)
oNode = OpenMaya.MDagPath()
selectionList.getDagPath(0, oNode)
return oNode
sel = cmds.ls(sl =1 )
crv = "curveShape1"
for s in sel :
pos = cmds.xform(s ,q = 1 , ws = 1 , t = 1)
u = getUParam(pos , crv)
name = s.replace("_LOC" , "_PCI")
pci = cmds.createNode("pointOnCurveInfo" , n = name )
cmds.connectAttr(crv + '.worldSpace' , pci + '.inputCurve')
cmds.setAttr(pci + '.parameter' , u )
cmds.connectAttr( pci + '.position' , s + '.t')
Hope it helps,