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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter