Extend Line

Extend Line

EnM4st3r
Advocate Advocate
850 Views
6 Replies
Message 1 of 7

Extend Line

EnM4st3r
Advocate
Advocate

What would be the easiest way to extend a Line to a surrounding Polyline?
So its just the length that changes.

EnM4st3r_0-1701847682179.png

Lets say i have the Line and Polyline as ename already, so i could start like that:
(defun extendtopol (line poly /)...)

0 Likes
Accepted solutions (4)
851 Views
6 Replies
Replies (6)
Message 2 of 7

hosneyalaa
Advisor
Advisor
Accepted solution
0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Use the intersect method with extendboth mode to find the intersection points, then somehow change the line - possibly by entmod.

 

See HERE 

0 Likes
Message 4 of 7

EnM4st3r
Advocate
Advocate
alright, i'll look into that. Thank you both!
0 Likes
Message 5 of 7

Sea-Haven
Mentor
Mentor
Accepted solution

I posted code that does what BeekeeCZ suggests now where is it. Ok found it modified to do only 1 inside *line.

; https://www cadtutor net/forum/topic/54831-trim-extend-to-polyline-boundry/

; simple trim extend of plines or lines inside say a rectang
; by AlanH Nov 2023

(defun c:wow ( / obj1 obj2 intpt oldsnap)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq obj1 (vlax-ename->vla-object (car (entsel "\nPick object boundary "))))
(setq obj2 (vlax-ename->vla-object (car (entsel "\nPick object to extend "))))
(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
  (if (= (vlax-get obj2 'ObjectName) "AcDbLine")
   (progn
    (vlax-put obj2 'startpoint (list (nth 0 intpt)(nth 1 intpt)(nth 2 intpt)))
    (vlax-put obj2 'endpoint (list (nth 3 intpt)(nth 4 intpt)(nth 5 intpt)))
   )
   (progn
    (vlax-put Obj2 'coordinate 0 (list (nth 3 intpt)(nth 4 intpt)(nth 5 intpt)))
    (vlax-put Obj2 'coordinate 1 (list (nth 0 intpt)(nth 1 intpt)(nth 2 intpt)))
   )
  )
(setvar 'osmode oldsnap)
(princ)
)
0 Likes
Message 6 of 7

calderg1000
Mentor
Mentor
Accepted solution

Regards @EnM4st3r 

Try this code, extend the inner line with a click on the boundary object

;;;___		 
(defun c:ext_line (/ snp lp snl x ln lnv lcd ps pe)
  (while
      (princ "\nPick object Boundary ")
    (setq
      snp (cadar (ssnamex (ssget "_+.:E:S" '((0 . "lwpolyline")))))
    )
     (setq
       lp  (mapcar
	     'cdr
	     (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget snp))
	   )
       snl (cadar (ssnamex (ssget "wp" lp '((0 . "line")))))
       ln  (list snp snl)
       lnv '()
     )
     (foreach x	ln
       (setq lnv (cons (vlax-ename->vla-object x) lnv))
     )
     (setq lcd (vlax-safearray->list
		 (vlax-variant-value
		   (vla-intersectwith (car lnv) (cadr lnv) acExtendboth)
		 )
	       )
	   ps  (list (car lcd) (cadr lcd) (caddr lcd))
	   pe  (cdr (member (caddr lcd) lcd))
     )
     (entmod
       (subst (cons 10 ps) (assoc 10 (entget snl)) (entget snl))
     )
     (entmod
       (subst (cons 11 pe) (assoc 11 (entget snl)) (entget snl))
     )
  )
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 7 of 7

EnM4st3r
Advocate
Advocate

thanks @Sea-Haven and @calderg1000 for the codes, both work well.
I have sort of a follow-up question but i think i better start a new post for that.
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/split-and-sort-a-pointlist/td-p/1242...

0 Likes