GetPointAtUV problem

877 views
Skip to first unread message

LeonTheProfessional

unread,
Mar 16, 2009, 2:35:30 PM3/16/09
to python_inside_maya
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

marcin

unread,
Mar 16, 2009, 2:56:04 PM3/16/09
to python_inside_maya
You have to get uv by using something like that:

u = mayaSDK.MScriptUitl.getFloat2ArrayItem(float2ParamUV,0,0)
v = mayaSDK.MScriptUitl.getFloat2ArrayItem(float2ParamUV,0,1)

Cheers,
Marcin

LeonTheProfessional

unread,
Mar 16, 2009, 3:41:38 PM3/16/09
to python_inside_maya
Thanks. I got this error:

# UnboundLocalError: local variable 'float2ParamUV' referenced before
assignment #

Also getFloat2ArrayItem(float2ParamUV,0,0), what do the 2nd and 3rd
arguments represent?




Thanks,
Light

LeonTheProfessional

unread,
Mar 16, 2009, 4:04:04 PM3/16/09
to python_inside_maya
Sorry I pasted the code somewhere else. But I got the same object
doesn't exist error now.




Thanks,
Light

marcin

unread,
Mar 16, 2009, 4:40:37 PM3/16/09
to python_inside_maya


On 16 Mar, 21:04, LeonTheProfessional <orionfl...@gmail.com> wrote:
> Sorry I pasted the code somewhere else. But I got the same object
> doesn't exist error now.
>

Sorry, but I made mistake. Your code is fine, but for proper results
you have to
increase tolerance in getPointAtUV. So replace getPointAtUV parameter
list with this:
mfnMesh.getPointAtUV(0, WSpoint, float2ParamUV,
mayaSDK.MSpace.kWorld,None,1.0)
When you do this it gives you correct results.

LeonTheProfessional

unread,
Mar 16, 2009, 4:44:44 PM3/16/09
to python_inside_maya
Thanks just tried it. Same error as before. I don't know what's going
on ):




Thanks,
Light

marcin

unread,
Mar 16, 2009, 5:08:53 PM3/16/09
to python_inside_maya
> Thanks just tried it. Same error as before. I don't know what's going
> on ):

It works strange at least for me :). When you specify proper polygonid
for
your uv point then getPointAtUV gives you correct result even with
tolerance 0.0.
When you specify wrong polygonid then you have to increase tolerance,
but then
getPointAtUV returns some weird result.

Ben Hindle

unread,
Mar 18, 2009, 4:53:41 AM3/18/09
to python_in...@googlegroups.com
hey everyone! i am having the same problem, i get the same error from this:

def getUVStuff(U, V, mesh):
    sel = om.MSelectionList()
    om.MGlobal.getSelectionListByName(mesh, sel)
    iter = om.MItSelectionList ( sel, om.MFn.kGeometric );
   
    WSpoint = om.MPoint()
   
    while not iter.isDone():

        dp = om.MDagPath()
        iter.getDagPath(dp)

        mObj = om.MObject()
        iter.getDependNode(mObj)       
       
        iterPolys = om.MItMeshPolygon(mObj)
       
       
        pArray = [U,V]
        util2 = om.MScriptUtil()  
        util2.createFromList (pArray,2)  
        float2ParamUV = util2.asFloat2Ptr()           
       
        while not iterPolys.isDone():
            iterPolys.getPointAtUV(WSpoint, float2ParamUV, om.MSpace.kObject)
            iterPolys.next()

        iter.next()
   
    return WSpoint


not sure what is going on here, but i tried just about everything i could think of to get this working, I'm out of ideas

any ideas would be greatly appreciated:)

thanks

Dean Edmonds

unread,
Mar 21, 2009, 10:17:29 AM3/21/09
to python_in...@googlegroups.com
On Mon, Mar 16, 2009 at 11:35, LeonTheProfessional <orion...@gmail.com> 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 #

Your code works for me in Maya 2009. What version of Maya are you using?

--
-deane

Jan

unread,
Aug 3, 2014, 3:52:26 AM8/3/14
to python_in...@googlegroups.com
Hi,

although this is quite an old thread, I wanted to post a work around for the sake of completeness:

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!
Reply all
Reply to author
Forward
0 new messages