pymel nurbsCurve.closestPoint(point,param *)

86 views
Skip to first unread message

hapgilmore

unread,
Aug 26, 2009, 6:43:23 PM8/26/09
to python_inside_maya
First off, i'm new to pymel, but loving how much it improves python in
maya.

I have a nurbsCurve PyNode, and a point (float array) and i'd like to
get the param value of the closest point.

I cant figure out the syntax to get this to work.

This works, but returns a point(float array):
<code>
point = [1,1,1]
closestPoint = myNurbsCurve.closestPoint(point)
</code>

This doesn't:
<code>
point = [1,1,1]
param = 0.0
closestPoint = myNurbsCurve.closestPoint(point,param)
</code>

Neither does this:
<code>
point = [1,1,1]
su = OpenMaya.MScriptUtil()
paramPtr = su.asDoublePtr()
closestPoint = myNurbsCurve.closestPoint(point,paramPtr)
param = su.getDouble(paramPtr)
</code>

Chad Dombrova

unread,
Aug 26, 2009, 10:06:17 PM8/26/09
to python_in...@googlegroups.com
That there is a bug.  

here's some background, if you care: 

pymel parses the api documentation to learn about the arguments of the api methods, because this cannot be gleaned through typical python inspection. The problem is that the api documentation contains many, many errors when it comes to specifying whether an argument is an input, or an output passed by reference c-style.  from the docs:

[in] toThisPoint The point to test 
[in] paramAsStart If true use the value pointed to by param as a starting point for the search. 
[in] param pointer to a double. If non-null, on successful returns this will contain the parameter value of the returned point. 
[in] tolerance The amount of error (epsilon value) in the calculation 
[in] space Specifies the coordinate system for this operation 
[out] ReturnStatus Status code

as you can see 'param' as marked as an input, but it's actually an output (aka a result).  the good folks at autodesk are working on fixing this.  Isn't that right, guys?  :)

when pymel generates the cached 'bin' files from the docs, it uses an algorithm that checks names, number of outputs, descriptions, etc, to attempt to detect correct these mistakes.  it also contains a manually maintained list of overrides.  in this case, we'll have to manually fix it. 

to fix this we would correct closestPoint to always return 2 values, a tuple of (Point, float).  

in pymel, you should never have to pass values by reference.  if you find that you have to, there's something wrong.

-chad

John Creson

unread,
Aug 28, 2009, 7:27:43 PM8/28/09
to python_in...@googlegroups.com
That's right Chad, we're working on it.

-JohnC

paul....@gmail.com

unread,
Jun 9, 2016, 3:52:11 PM6/9/16
to Python Programming for Autodesk Maya
Looks like this is still broken.

NurbsCurve.closestPoint() is still expecting param ptr.

Reply all
Reply to author
Forward
0 new messages