Hi,
although this is quite an old thread, I wanted to post a work around for
the sake of completeness
<http://www.dict.cc/englisch-deutsch/for+the+sake+of+completeness.html>:
import maya.OpenMaya as om
import maya.cmds as cmds
def GetDagPath(nodeName):
sel = om.MSelectionList()
om.MGlobal.getSelectionListByName(nodeName, sel)
dp = om.MDagPath()
sel.getDagPath(0,dp)
return dp
def UvCoordToWorld(U, V, mesh):
mfnMesh = om.MFnMesh(GetDagPath(mesh))
numFaces = mfnMesh.numPolygons()
WSpoint = om.MPoint(0.0,0.0,0.0)
util2 = om.MScriptUtil()
util2.createFromList ((U, V),2)
float2ParamUV = util2.asFloat2Ptr()
for i in range(numFaces):
try:
mfnMesh.getPointAtUV(i,WSpoint, float2ParamUV, om.MSpace.kWorld)
break; #point is in poly
except:
continue #point not found!
return WSpoint
f = UvCoordToWorld (0.5, 0.5, 'pSphereShape1')
print [f[0], f[1], f[2]]
Cheers!
On Monday, 16 March 2009 19:35:30 UTC+1, LeonTheProfessional wrote:
>
> Hi all,
>
> I am trying to use the getPointAtUV function from python, but get this
> error:
>
> Code:
>
> # Error: (kFailure): Object does not exist
> # Traceback (most recent call last):
> # File "<maya console>", line 23, in <module>
> # File "<maya console>", line 20, in UvCoordToWorld
> # RuntimeError: (kFailure): Object does not exist #
>
> The code is this:
>
> Code:
>
> import maya.OpenMaya as mayaSDK
> import maya.cmds as maya
>
> def GetDagPath(nodeName):
> sel = mayaSDK.MSelectionList()
> mayaSDK.MGlobal.getSelectionListByName(nodeName, sel)
> dp = mayaSDK.MDagPath()
> sel.getDagPath(0,dp)
> return dp
>
> def UvCoordToWorld(U, V, mesh):
> mfnMesh = mayaSDK.MFnMesh(GetDagPath(mesh))
> numFaces = mfnMesh.numPolygons()
> WSpoint = mayaSDK.MPoint(0.0,0.0)
>
> util2 = mayaSDK.MScriptUtil()
> util2.createFromList ((U, V),2)
> float2ParamUV = util2.asFloat2Ptr()
>
> mfnMesh.getPointAtUV(0, WSpoint, float2ParamUV,
> mayaSDK.MSpace.kWorld)
>
> return WSpoint
>
> f = UvCoordToWorld (0.5, 0.5, 'lowreshead')
> print [f[0], f[1]]
>
>
> Anyone knows how to do this properly. Maya python is very annoying.
>
>
>
>
> Thanks,
> Light
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/e2df332a-0edc-4e24-ad4c-232dd0a91dba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.