closestPointOnPoly

109 views
Skip to first unread message

thirstydevil

unread,
Mar 14, 2017, 1:40:59 PM3/14/17
to Python Programming for Autodesk Maya
So I've been having issues today with all types of rivet scripts, the closets point on poly node or anything that is essentially using maya.OpenMaya.MSpace.getUVAtPoint

If I run the below just once I get [0,0] as the uv position.  If I run it several times it will eventually return the correct result.  Maya 2017 update 3.

Anyone experiencing this, is it normal?


-Dave

Ian Waters

unread,
Mar 14, 2017, 1:43:18 PM3/14/17
to python_in...@googlegroups.com
Hey Dave,

Not a solution to your problem, but did you try the Surface Attach tool that comes with Maya Muscle? We’ve found it to be a lifesaver.
Deform > Muscle > Bonus Rigging > Surface Attach

Worth a shout :)
Ian

--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/cc04ad67-2c28-4e30-bb4d-d9766ac4c6db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Moulder

unread,
Mar 14, 2017, 2:14:04 PM3/14/17
to python_inside_maya
Just tried it, works like a charm.  I guess that when you've used follicles so so long you don't look else where.  Doesn't solve the issue above but if it's solid I'll swap the code out to this function call.

Thanks Ian!

-Dave

On Tue, Mar 14, 2017 at 5:43 PM, Ian Waters <water...@gmail.com> wrote:
Hey Dave,

Not a solution to your problem, but did you try the Surface Attach tool that comes with Maya Muscle? We’ve found it to be a lifesaver.
Deform > Muscle > Bonus Rigging > Surface Attach

Worth a shout :)
Ian
On 14 Mar 2017, at 17:40, thirstydevil <da...@thirstydevil.co.uk> wrote:

So I've been having issues today with all types of rivet scripts, the closets point on poly node or anything that is essentially using maya.OpenMaya.MSpace.getUVAtPoint

If I run the below just once I get [0,0] as the uv position.  If I run it several times it will eventually return the correct result.  Maya 2017 update 3.

Anyone experiencing this, is it normal?


-Dave

--
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 python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1561608D-5354-4611-9867-D8716AA374CB%40gmail.com.

For more options, visit https://groups.google.com/d/optout.

Andres Weber

unread,
Mar 15, 2017, 12:16:31 AM3/15/17
to Python Programming for Autodesk Maya
I commented on your gist but I'll add here just in case you don't check that often:

The problem with this code is specifying your world space as a string value. It requires an integer and for maximum future proofing you should use the pre-defined one from the api:

OpenMaya.MSpace.kWorld

Feed that into your second argument instead of "world" and assuming that you've iterated through the faces correctly, it should return the correct result.


Help on built-in function getUVAtPoint:

getUVAtPoint
(...)
 getUVAtPoint
(point, space=MSpace.kObject, uvSet='') -> (float, float, int)

 
Returns a tuple containing the u and v coordinates of the point on
 the mesh closest to the given point
, and the ID of the face
 containing that closest point.

Andres Weber

unread,
Mar 15, 2017, 12:22:11 AM3/15/17
to Python Programming for Autodesk Maya
Sorry, just realized you're using API 1.0.  I doubt that helps your situation and I can't recall the differences in those calls.

David Moulder

unread,
Mar 15, 2017, 10:11:30 AM3/15/17
to python_inside_maya
Thanks for pointing this out Andres,

It's not obvious from the gist but this uses PyMel.  It's wrapping of the API lets you use strings for the space param.  I believe its using a pymel enum under the hood before constructing the MSpace object.

Cheers

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
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 python_inside_maya+unsubscribe@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Paul Molodowitch

unread,
Mar 15, 2017, 1:14:32 PM3/15/17
to python_inside_maya
Hi David  - a few tips when seeking help on this list:

- Whenever possible, provide all the code necessary to set up the scene to test
- Provide all the pertinent code to replicate the problem
- This will generally mean extracting and simplifying your code. Do so.

Doing this will mean more work on your part - often extracting the pertinent piece so it can be run in isolation is not trivial - but it's worth it.  When troubleshooting, it's generally something you want to do anyway - it will help eliminate extra variables, and generally speed up your test / retry cycle a lot.  For others, it makes it much easier for them to diagnose your problem and help, as well as shows that you've taken some time to try to solve the issue on your own.

In your case - we have no means of replicating your problem, so we have no way of knowing what's going on.  Is it a problem with the getUVAtPoint, or other code? And the bits of extra code you've chosen to include actually further confuse the issue, not clarify.  You include an outer loop, but don't even use the variable you're iterating over (x) in your snippet. How is "face" even getting changed?

This code seems to work for me - and also provides a good example of a self-contained code sample:

https://gist.github.com/elrond79/e920bd1fa8b6d5c2345dc32369bda4f5

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
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 python_inside_m...@googlegroups.com.

--
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 python_inside_m...@googlegroups.com.



--
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABD4PkRWdgJ4dPUwVX%3De2NCC7R6PgVe6w-_7gCs9eLqvpgoD2g%40mail.gmail.com.

David Moulder

unread,
Mar 15, 2017, 4:40:15 PM3/15/17
to python_inside_maya
Hi Paul,

My apologies, you're right, I should have formed a better question with a simple example file but I suppose the heat of production is getting to me, thankfully Ian's answer was the perfect timely alternative.  Thanks Ian!

Today I can't replicate the issue, I was hoping to reply with a full example and cut down Maya file.  I've opened the same character file, doing the same thing and it's working as expected.  It's like when you report an IT problem and when the IT guy stands next to you it's working as expected, oh well, I digress.

I've updated the gist with the full code.  I've turned down the loop to 1 iteration (line 70) in my testing yesterday it had to be at 50 iterations to be sure it correctly found the UV position.  If I do find a repeatable mesh I'll definitely update this thread with examples. 

Thanks again and thanks Ian

-Dave 





To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.



--
David Moulder
Technical Animator / Artist

--
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 python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAssL7YHfV4UjZhOSzD04WrM2HW5UcA-LqwRyu7hKA3pqiodkA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Paul Molodowitch

unread,
Mar 16, 2017, 3:08:54 PM3/16/17
to python_inside_maya
Ahhh... now the loop makes sense. I didn't understand why it was there, and didn't put it together with the fact that you mentioned you had to run it several times.  Apologies!

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
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 python_inside_m...@googlegroups.com.

--
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 python_inside_m...@googlegroups.com.



--
David Moulder
Technical Animator / Artist

--
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 python_inside_m...@googlegroups.com.

--
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 python_inside_m...@googlegroups.com.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABD4PkQ3Y6EPEC7ptHtqH%2BDQ_9tOVe2RVPc0nnWDEQ5dMjG9pg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages