rs.MeshClosestPoint doesn't work

when i use the example code of MeshClosestPoitn :

#! python 3
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select mesh", rs.filter.mesh)
point = rs.GetPoint("Pick test point")
intersect = rs.MeshClosestPoint(obj, point)
if intersect: rs.AddPoint(intersect)

I got those error message:

  Traceback (most recent call last):
  File "file:///C:/Users/stinson/.rhinocode/stage/v13jcwul.mvn", line 36, in <module>
  File "C:\Users\stinson\.rhinocode\py39-rh8\site-rhinopython\rhinoscript\mesh.py", line 603, in MeshClosestPoint
    face, closest_point = mesh.ClosestPoint(point, tolerance)
TypeError: No method matches given arguments for Mesh.ClosestPoint: (<class 'Rhino.Geometry.Point3d'>, <class 'float'>)

For i know, those code works in rhino 5 and rhino 7, but not works in rhino 8,
Is there any solution ?
My environment is : Rhino 8.4.24044.15001

The MeshClosestPoint is fixed in 8.5 I think, but I see at least in internal 8.6 another problem

@eirannejad the Point3d class appears now to be givin all three points when doing intersect[0]. This makes coerce3dpoint() fail.

addendum: the AddPoint error happens also in 8.5. I have logged for @eirannejad : RH-80900 rhinoscriptsyntax AddPoint fails when given Point3d instance

1 Like

The problem is intersect is a tuple of a point and index of the mesh face that the point in on:

Python 3 and IronPython 2

Rhino 7 throws a similar error:

Rhino_2CQH49gxnv

Try:

intersect, face_index = rs.MeshClosestPoint(obj, point)
1 Like