-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetUParam.py
More file actions
36 lines (30 loc) · 1.19 KB
/
Copy pathgetUParam.py
File metadata and controls
36 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 == False:
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