getUVAtPoint and a type error

Every time I think I’m starting to get a handle on the maya api, it goes and punches me in the face. Alas. Did a bit of searching and came up empty.

So I’m getting the following error:

# TypeError: in method 'MFnMesh_getUVAtPoint', argument 2 of type 'MPoint &' # 

The offending code is:


        pArray = [0.0,0.0]
        x1 = OpenMaya.MScriptUtil()
        x1.createFromList( pArray, 2 )
        uvPoint = x1.asFloat2Ptr()
        uvSet = None
        closestPolygon=None
        uvReturn = meshFn.getUVAtPoint(hitPoint,uvPoint,OpenMaya.MSpace.kWorld,uvSet,1)

I got the 2 point array handler from Mattias' Notes: float2 and float3 in Maya Python API and I can’t get a handle on why this isn’t working. From what I’ve been able to find it seems to be working for them fine.

In the same tool i’m getting mesh intersections with no issue at all it just seems that this one command is throwing me for a loop.

Any help would be appreciated.

“argument 2” is referring to the hitPoint object, not the uvPoint. Since getUVAtPoint is a method of the meshFn class, the first argument will always be self, and the 2nd will be the first one you pass in.

Your error is because your hitPoint object isn’t an MPoint. How are you getting your hitPoint object?

Thanks for the quick reply capper. The hitPoint is an MFloatPoint and that portion has been working for a while now. Is an MPoint no longer an Mpoint after it has had a result fed into it?

hitPoint = OpenMaya.MFloatPoint()

The result of that meshFn.closestIntersection comes back as hitPoint.x,y,z just dandy. Maybe I’m not clear on the MPoint yet?

MPoint and MFloatPoint are two different objects.

If you look in the docs, you’ll see they specify two different types:

bool closestIntersection	(const MFloatPoint...
MStatus getUVAtPoint	(MPoint....

You are trying to pass an MFloatPoint to getUVAtPoint, but it is expecting an MPoint so it throws a type error. One of the constructors of an MPoint takes an MFloatPoint as a argument:

MPoint (const MFloatPoint &src)
 	Class constructor. 

So after you fill your hitPoint with the intersection, call

hitMPoint = om.MPoint(hitPoint)

You can then pass hitMPoint to getUVAtPoint

Capper, you’ve capped the flag today. You rock! :slight_smile: