Hi,
I have a point on a horizontal line and want to measure distance from it to a curve. When I pick a point and a curve, the routine returns the linear distance between them. Could someone please tell me how to do it?
Thanks in advace.
Khanh.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@maikhanhmst wrote:
Hi,
I have a point on a horizontal line and want to measure distance from it to a curve. When I pick a point and a curve, the routine returns the linear distance between them. Could someone please tell me how to do it?
Thanks in advace.
Khanh.
(defun c:demo (/ a b) (setq a (getpoint "\nPick point on Horizontal line \:")) (setq b (Car (entsel "\nSelect Curve Line:"))) (alert (rtos (distance (osnap a "nea") (vlax-curve-getClosestPointToProjection b (osnap a "nea") '(0.0 1.0 0.0) ) ) ) ) )
Hi,
Many thanks. That works exactly what I wanted. As a part of my learning AutoLisp, I wondered how (osnap a "nea") work, so when I run your routine, I deleted the statements, but it run well. So what happen if I delete it. Could you mind helping me understand this?
Khanh.
@maikhanhmst wrote:
Hi,
Many thanks. That works exactly what I wanted. As a part of my learning AutoLisp, I wondered how (osnap a "nea") work, so when I run your routine, I deleted the statements, but it run well. So what happen if I delete it. Could you mind helping me understand this?
Khanh.
(osnap a "nea") ;<-- that line ensures the distance will be taken from a point touching the line object.
Now if during the prompt from pickpoint you already set a snap lets say "nea" or osmode set to 512 then the line above can be omitted. i meant just the a variable will be enough.
another way to write the code is
(defun c:demo (/ a b) (setq a (getpoint "\nPick point on Horizontal line :")) (setq b (CAr (nentselp a)));<-- select line via coordinates (setq c (Car (entsel "\nSelect Curve Line:"))) (alert (rtos (distance (setq a (vlax-curve-getclosestpointto b a));<-point on the line (vlax-curve-getClosestPointToProjection c a '(0.0 1.0 0.0) ) ) ) ) )
HTH
I got it. If the routine doesn't include (osnap a "nea") and the osmode isn't 512 or osnap "nea" setting not picked in the osnap box, the distance isn't taken correctly.
Thanks.