Jump to content

Extend line with a line tangent to it


dexus

Recommended Posts

I made a short function that extends a line with an arc tangent to the line you selected.

The function works exactly the same as continuing a polyline only lets you select an object to start with.

 

Anyway, I decided to share it, so here it is:

; Extend line with a line tangent to it - dexus
(defun c:tan (/ ang obj obj-end obj-start pt select-data tanpt ~cmd *error*)
    (defun *error* (msg)
        (setvar "cmdecho" ~cmd)
        (princ msg)
        (princ)
    )
    (setq ~cmd (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (while (not select-data)
		(setq select-data (entsel "\nSelect line to extend: "))
		(if select-data (progn
			(setq	obj (vlax-ename->vla-object (car select-data))
				obj-start (vlax-curve-getstartpoint obj)
				obj-end (vlax-curve-getendpoint obj)
				pt (trans (cadr select-data) 1 0))
			(if (< (distance obj-start pt) (distance obj-end pt))
				(setq	tanpt obj-start
					ang (angle '(0 0 0) (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj tanpt))))
				(setq	tanpt obj-end
					ang (angle (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj tanpt)) '(0 0 0)))
			)
			(command "_.line" "_none" (polar tanpt ang 50.0) "_none" tanpt ""
		 	 	 "_erase" "_l" ""
		 	 	 "_.pline" "_none" tanpt "_arc" pause)
		) (princ "\nNothing was selected, Please select a line!"))
	)
	(setvar "CMDECHO" ~CMD)
	(princ)
)

Hope this is useful to some of you. It was for me since I have to draw a lot of shapes that are tangent.

Edited by dexus
  • Thanks 2
Link to comment
Share on other sites

I like it, and its useful for me!

Heres a little constructive note, if you don't mind -

Replace the while block with and, and change the (setq select-data ...) :

(while (not select-data)
  (setq select-data (entsel "\nSelect line to extend: "))
  ; <Your code here>   
); while

with:

(and 
  (setq select-data
    (
      (lambda ( / p r ) (setvar 'errno 0)
        (while (/= 52 (getvar 'errno)) (setq p (entsel "\nSelect line to extend <exit>: "))
          (cond 
            ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0) )
            ( (not p) )
            ( (setvar 'errno 52) (setq r p) )
          ); cond 
        ); while 
        r 
      ); lambda 
    )
  ); setq select-data
  ; <Your code here>        
); and

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...