GetPointAtUV problem

Hi all,

I am trying to use the getPointAtUV function from python, but get this error:

# 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:

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

So, I must apologize for not knowing much about the python particulars of the Api, and I hope by now this has been solved, but in C++, you can check for success of function set initialization. I would check there first. If you do something like grab the transform instead of the shape, the mfnmesh will probably fail. Barring an actual check to the mstatus, you could just print the numfaces. Zero is a pretty good indication the MFN missed.

If this wasn’t your problem, I’m very interested in what it was, because I am currently toying with the idea of doing more plugin work in python instead of C++.

Cheers! -Lith
(apologies for dumb autocorrect typos, sent from phone)

Hey man,

Thanks for replying. It’s pretty strange, I tried a couple different things but it failed. I just tried the shape node, but same error.

I think the python integration in maya is terrible, syntax wise, etc. Still better than MEL IMO.

Cheers,
Light

I actually poked at it just now, and your code is right, but the Api is wacky. Instead of returning mstatus failed on a miss, the python api throws an exception if the uv is not within the face. All maya is trying to do is tell you it couldn’t find anything. It looks like you need to manually try/catch this, and make sure you’re on the right face. The good and bad news is that your original code is perfectly valid.

Cheers!

Thanks. You are right. It should work with your suggestion I think. Too bad, these aren’t done right, or even documented.

Cheers,
Light