getclosestpointto vs. (osnap p "_near")

getclosestpointto vs. (osnap p "_near")

john.uhden
Mentor Mentor
923 Views
3 Replies
Message 1 of 4

getclosestpointto vs. (osnap p "_near")

john.uhden
Mentor
Mentor

 

In a new drawing with just one object, a 3D polyline, I used (entsel) to select a segment, which returns
the entity name (e) and the pick point.(p). However... (vlax-curve-getclosestpointto e p)   and (osnap p "_near") return different results though neither is an endpoint (which one might suspect since the pick point's
Z value is 0.0)   Is there a logical reason for this? Which answer should I trust?

John F. Uhden

0 Likes
Accepted solutions (1)
924 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

Osnapping to the NEArest point gives you the nearest point from the point of view of the current view direction.  Not the current Coordinate System, either, but the current view, even if you're not looking in plan view in the current CS -- as though everything is flattened onto the screen.  GetClosestPointTo gives you the closest point in 3D.  So which you should "trust" depends on what you want to do with the result.

Kent Cooper, AIA
0 Likes
Message 3 of 4

john.uhden
Mentor
Mentor

That makes sense.  Thanks, Kent.

 

What I also found out is that finding the (osnap) depends on the size of aperture.  If you are zoomed in too tight, it might return nil.

John F. Uhden

0 Likes
Message 4 of 4

phanaem
Collaborator
Collaborator
Accepted solution

Hi John

 

The point returned by (entsel) is always in the current UCS, at elevation zero.

The closest point on selected object is almost never the visually closest point on the object.

You can use this to get the same point as the one acquired with osnap.

 

(vlax-curve-getclosestpointtoprojection e (trans p 1 0) (trans (getvar 'viewdir) 1 0 T))

The result is in WCS.