Author Topic: extend both ends of a polyline to another that contains it  (Read 3736 times)

0 Members and 1 Guest are viewing this topic.

AwAD

  • Guest
extend both ends of a polyline to another that contains it
« on: October 29, 2018, 06:19:37 PM »
hello every one,
I've tried the (command "extend" boundary-entity "" line-entity "") that only extended one end,
is there is a way to do both ends without the user selecting them ?

Dlanor

  • Bull Frog
  • Posts: 263
Re: extend both ends of a polyline to another that contains it
« Reply #1 on: October 30, 2018, 07:41:28 AM »
Try this

Code - Auto/Visual Lisp: [Select]
  1. (defun c:x2ends ( / )
  2.   (setq b_ent (car (entsel "\nSelect Boundary Line Entity : "))
  3.         x_ent (car (entsel "\nSelect Line to Extend : "))
  4.         pt1 (vlax-curve-getstartpoint x_ent)
  5.         pt2 (vlax-curve-getendpoint x_ent)
  6.   )
  7.   (command "_extend" b_ent "" (nentselp pt1) (nentselp pt2))
  8. )
  9.  

AwAD

  • Guest
Re: extend both ends of a polyline to another that contains it
« Reply #2 on: October 30, 2018, 07:59:20 AM »
thank's a lot for your effort,
I tried a similar concept, however (nentselp) doesn't work most of the time unfortunately.
It's related to the current view and the zoom level, even when changing 'pickpox system variable to 1, It's still unreliable, And to 0 it fail's to select half of the time.
« Last Edit: October 30, 2018, 09:08:21 AM by AwAD »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: extend both ends of a polyline to another that contains it
« Reply #3 on: October 30, 2018, 10:57:55 AM »
You could try temporarily to zoom on the bounding box of the "boundary object" (focus) -

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / e1 e2 p1 p2 cad )
  2.   (if
  3.     (and
  4.       (setq e1 (car (entsel "\nSelect Boundary Line Entity : ")))
  5.       (setq e2 (car (entsel "\nSelect Line to Extend : ")))
  6.       (setq p1 (vlax-curve-getStartPoint e2))
  7.       (setq p2 (vlax-curve-getEndPoint e2))
  8.     )
  9.     (progn
  10.       (setq cad (vlax-get-acad-object))
  11.       (vla-GetBoundingBox (vlax-ename->vla-object e1) 'll 'ur)
  12.       (vla-ZoomWindow cad ll ur)
  13.       (vla-ZoomScaled cad 0.9 acZoomScaledRelative)
  14.       (command "_extend" e1 "" (nentselp p1) (nentselp p2) "")
  15.       (repeat 2 (vla-ZoomPrevious cad))
  16.     )
  17.   )
  18.   (princ)
  19. )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: extend both ends of a polyline to another that contains it
« Reply #4 on: October 30, 2018, 11:58:43 AM »
Testing a bit, more reliable would be to zoom on the pair of objects, since focusing on one won't guarantee successful extend to the other:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / e1 e2 p1 p2 cad )
  2.   (if
  3.     (and
  4.       (setq e1 (car (entsel "\nSelect Boundary Line Entity : ")))
  5.       (setq e2 (car (entsel "\nSelect Line to Extend : ")))
  6.       (setq p1 (vlax-curve-getStartPoint e2))
  7.       (setq p2 (vlax-curve-getEndPoint e2))
  8.     )
  9.     (progn
  10.       (
  11.         (lambda ( cad eL / ll ur pL )
  12.           (foreach e eL
  13.             (vla-GetBoundingBox (vlax-ename->vla-object e) 'll 'ur)
  14.             (setq pL (cons (mapcar 'vlax-safearray->list (list ll ur)) pL))
  15.           ); foreach  
  16.           (apply 'vlax-invoke
  17.             (append (list cad 'ZoomWindow)
  18.               (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b)))
  19.                 '(min max)
  20.                 (list (mapcar 'car pL) (mapcar 'cadr pL))
  21.               )
  22.             )
  23.           )
  24.           (vla-ZoomScaled cad 0.9 acZoomScaledRelative)
  25.         )
  26.         (setq cad (vlax-get-acad-object))
  27.         (list e1 e2)
  28.       )
  29.       (command "_extend" e1 "" (nentselp p1) (nentselp p2) "")
  30.       (repeat 2 (vla-ZoomPrevious cad))
  31.     )
  32.   )
  33.   (princ)
  34. )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

AwAD

  • Guest
Re: extend both ends of a polyline to another that contains it
« Reply #5 on: October 30, 2018, 03:31:00 PM »
Testing a bit, more reliable would be to zoom on the pair of objects, since focusing on one won't guarantee successful extend to the other:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / e1 e2 p1 p2 cad )
  2.   (if
  3.     (and
  4.       (setq e1 (car (entsel "\nSelect Boundary Line Entity : ")))
  5.       (setq e2 (car (entsel "\nSelect Line to Extend : ")))
  6.       (setq p1 (vlax-curve-getStartPoint e2))
  7.       (setq p2 (vlax-curve-getEndPoint e2))
  8.     )
  9.     (progn
  10.       (
  11.         (lambda ( cad eL / ll ur pL )
  12.           (foreach e eL
  13.             (vla-GetBoundingBox (vlax-ename->vla-object e) 'll 'ur)
  14.             (setq pL (cons (mapcar 'vlax-safearray->list (list ll ur)) pL))
  15.           ); foreach  
  16.           (apply 'vlax-invoke
  17.             (append (list cad 'ZoomWindow)
  18.               (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b)))
  19.                 '(min max)
  20.                 (list (mapcar 'car pL) (mapcar 'cadr pL))
  21.               )
  22.             )
  23.           )
  24.           (vla-ZoomScaled cad 0.9 acZoomScaledRelative)
  25.         )
  26.         (setq cad (vlax-get-acad-object))
  27.         (list e1 e2)
  28.       )
  29.       (command "_extend" e1 "" (nentselp p1) (nentselp p2) "")
  30.       (repeat 2 (vla-ZoomPrevious cad))
  31.     )
  32.   )
  33.   (princ)
  34. )

THANK YOU VERY MUCH,
that works great.
 :yay!:

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: extend both ends of a polyline to another that contains it
« Reply #6 on: October 30, 2018, 04:29:41 PM »
THANK YOU VERY MUCH,
that works great.
 :yay!:

Thanks, however address that to Dlanor.. I couldn't figure out the nentselp trick within a command call bymyself  :roll:
And the zooming stuff are not that hard to implement.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: extend both ends of a polyline to another that contains it
« Reply #7 on: October 31, 2018, 02:54:45 AM »
It’s very easy started to do something, you just pick outside pline then inside pline and do a intersectwith with extend option and it returns the two new intersection points as a list. You then just redo the pline co-ores. I started at home using this and just had to sort out the build new pline co-ores list and you just vlax-putcoordinates. On a IPad at moment wil try later when home to finish pushed for time and moment.
A man who never made a mistake never made anything

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: extend both ends of a polyline to another that contains it
« Reply #8 on: October 31, 2018, 12:32:18 PM »
I would avoid nentselp. Creating your own 'entsel-list' is probably more reliable:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ExtendBothEnds ( / e1 e2)
  2.   (if
  3.     (and
  4.       (setq e1 (car (entsel "\nSelect Boundary Line Entity : ")))
  5.       (setq e2 (car (entsel "\nSelect Line to Extend : ")))
  6.     )
  7.     (progn
  8.       (setvar 'cmdecho 0)
  9.       (command
  10.         "_extend"
  11.         e1
  12.         ""
  13.         (list e2 (trans (vlax-curve-getstartpoint e2) 0 1))
  14.         (list e2 (trans (vlax-curve-getendpoint e2) 0 1))
  15.         ""
  16.       )
  17.       (setvar 'cmdecho 1)
  18.     )
  19.   )
  20.   (princ)
  21. )

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: extend both ends of a polyline to another that contains it
« Reply #9 on: October 31, 2018, 08:42:41 PM »
I would avoid nentselp. Creating your own 'entsel-list' is probably more reliable:

I like that Roy!
..unfortunately no like button to hit for your post, so :thumbsup:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: extend both ends of a polyline to another that contains it
« Reply #10 on: November 01, 2018, 07:43:38 AM »
Try this would appreciate to know if it works with arcs.

Code: [Select]
(defun c:plout ( / obj1 obj2 co-ords x y lst)
(setq obj1 (vlax-ename->vla-object (car (entsel "Pick outside object"))))
(setq obj2 (vlax-ename->vla-object (car (entsel "Pick inner object"))))
(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
(setq co-ords (vlax-safearray->list (vlax-variant-value (vlax-get-property obj2 'Coordinates))))
(setvar 'osmode 0)
(setq lst '())
(setq lst (cons (nth 1 intpt)lst))
(setq lst (cons (nth 0 intpt)lst))
(setq x (/ (length co-ords)2))
(setq y 2)
(repeat (- x 2)
(setq lst (cons (nth (+ y 1) co-ords)lst))
(setq lst (cons (nth y co-ords)lst))
(setq y (+ y 2))
)
(setq lst (cons (nth 4 intpt)lst))
(setq lst (cons (nth 3 intpt)lst))
(vlax-put obj2 'Coordinates lst)
)
(c:plout)
A man who never made a mistake never made anything

AwAD

  • Guest
Re: extend both ends of a polyline to another that contains it
« Reply #11 on: November 03, 2018, 02:29:53 PM »
Try this would appreciate to know if it works with arcs.
Yes that works great  :yes:.
THANK YOU.
It even fix the issue when one end of the inner polyline is not inside the outer one, "intersecting with it". :yay!:

However when the inner polyline have arc in it or is just an arc, some times it works great, others strange things happen like
flipping the arc "it's center is mirrored to the other direction", the polyline is changed completely that i couldn't understand what happened.

The Previous solution is also great, however when their is an end that is outside and also the end of an arc, It is extended all the way around to the other side of the outer creating a giant circle  :cry:.

I attached a sample file if you want to try.

Finally I searched online and came up with a not very efficient solution witch is to extend all the inner lines with a known amount, Then breaking them at their intersection points with the outer lines, After that deleting all the lines that are shorter than or equal to the  known amount.

THANKS VERY MUCH TO ALL YOU WHO HELPED ME, I LEARNED A LOT FROM YOU IN THAT TOPIC.