Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help: Autolisp routine for measuring vertical distance from a point to a curve

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
maikhanhmst
404 Views, 4 Replies

Help: Autolisp routine for measuring vertical distance from a point to a curve

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.

4 REPLIES 4
Message 2 of 5
pbejse
in reply to: maikhanhmst


@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)
		    )
	  )
    )
  )
)

 

Message 3 of 5
maikhanhmst
in reply to: pbejse

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.

Message 4 of 5
pbejse
in reply to: maikhanhmst


@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

Message 5 of 5
maikhanhmst
in reply to: pbejse

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. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost