Author Topic: Stretch multiple base point polylines to different distance  (Read 3493 times)

0 Members and 1 Guest are viewing this topic.

m4rdy

  • Newt
  • Posts: 62
Stretch multiple base point polylines to different distance
« on: August 13, 2016, 05:26:52 AM »
Hi all,

Is this possible to stretch  polylines with multiple base point to different distance but same direction?


m4rdy


Autocad 2007, Windows XP

m4rdy

  • Newt
  • Posts: 62
Re: Stretch multiple base point polylines to different distance
« Reply #1 on: August 19, 2016, 01:44:12 PM »
I'm glad it works although far from perfect.

Code: [Select]
(defun c:Test2 (/ toLine p1 p2 ss lst0 lst1 Pintobj vtx_pline list_vtx_pline)
  (if
    (and (setq toLine (vlax-ename->vla-object (car (entsel "\nSelect Line: "))))
     (setq p1 (getpoint "\nSpecify First Point: "))
     (setq p2 (getpoint "\nSpecify Second Point: " p1))
     (setq ss (apply 'ssget (append (list "_C") (mapcar '(lambda (foo) (apply 'mapcar (cons foo (list p1 p2)))) '(min max))
            (list '((0 . "*LINE"))))))
     (setq lst0 ((lambda (l / i)  (setq i (lm:getobjintersectionsinss l ss)) (vla-delete l) i)
          (vlax-ename->vla-object  (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2))))))
       ) ;_and
     (progn
       ;; Find intersection between line and selection
       (setq Pintobj (lm:getobjintersectionsinss toLine ss))

       ;;(princ Pintobj) ;_for testing

       (setq cadrm (mapcar 'cadr (ssnamex ss)))

       ;; Make list (ename point_intersection)
       (setq lst1 (mapcar 'list cadrm lst0))

       (foreach    n lst1
     (setq p (fix
           (vlax-curve-getparamatpoint
             (car n)
             (vlax-curve-getclosestpointtoprojection
               (car n)
               (trans (cadr n) 1 0)
               '(0.0 0.0 1.0)
             )
           )
         )
     ) ;_setq p
     (setq vtx_pline (list (trans (vlax-curve-getpointatparam (car n) p) 0 1)))

     ;;(princ vtx_pline) ;_for testing

     (setq list_vtx_pline (append list_vtx_pline vtx_pline)) ;_This is Start point of Selected Segment PLINES as base point of STRETCH:

       ) ;_foreach
       ;;(princ list_vtx_pline) ;_for testing

       (setq data (mapcar 'list cadrm list_vtx_pline pintobj))

       (foreach    m data
            (vl-cmdf "_.stretch" (car m) "" "_non" (cadr m) (caddr m)))
     ) ;_progn
  ) ;_if
  (princ)
) ;_defun

(defun lm:getobjintersectionsinss (obj ss)
  ;; © Lee Mac 2010
  ((lambda (i / j a b ilst)
     (while (setq e (ssname ss (setq i (1+ i))))
       (setq ilst (append ilst
              (lm:groupbynum
                (vlax-invoke
                  obj
                  'intersectwith
                  (vlax-ename->vla-object e)
                  acextendnone
                )
                3
              )
          )
       )
     )
   )
    -1
  )
)

;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
(defun LM:GroupByNum (l n / r)
  (if l
    (cons
      (reverse (repeat n
         (setq r (cons (car l) r)
               l (cdr l)
         )
         r
           )
      )
      (LM:GroupByNum l n)
    )
  )
)

m4rdy
Autocad 2007, Windows XP

m4rdy

  • Newt
  • Posts: 62
Re: Stretch multiple base point polylines to different distance
« Reply #2 on: August 19, 2016, 01:49:47 PM »
Duh,
Spoke too soon.
My code is just moving all pline, not stretching like what i want.
 :tickedoff: :knuppel2:
« Last Edit: August 19, 2016, 02:01:49 PM by m4rdy »
Autocad 2007, Windows XP

xdcad

  • Bull Frog
  • Posts: 486
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Stretch multiple base point polylines to different distance
« Reply #4 on: December 11, 2023, 03:12:34 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:stretch-vert-curve ( / ptonline rlw ss s c sn ip pts ptt vec ptn k n enx )
  2.  
  3.  
  4.   (defun ptonline ( p1 p p2 )
  5.     (equal (distance p1 p2) (+ (distance p1 p) (distance p p2)) 1e-8)
  6.   )
  7.  
  8.   (defun rlw ( lw / e x1 x2 x3 x4 x5 x6 )
  9.     ;; by ElpanovEvgeniy
  10.     (if (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
  11.       (progn
  12.         (foreach a1 e
  13.           (cond
  14.             ( (= (car a1) 10) (setq x2 (cons a1 x2)) )
  15.             ( (= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4)) )
  16.             ( (= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3)) )
  17.             ( (= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5)) )
  18.             ( (= (car a1) 210) (setq x6 (cons a1 x6)) )
  19.             ( t (setq x1 (cons a1 x1)) )
  20.           )
  21.         )
  22.         (entmod
  23.           (append (reverse x1)
  24.             (append
  25.               (apply 'append
  26.                 (apply 'mapcar
  27.                   (cons 'list
  28.                     (list x2
  29.                       (cdr (reverse (cons (car x3) (reverse x3))))
  30.                       (cdr (reverse (cons (car x4) (reverse x4))))
  31.                       (cdr (reverse (cons (car x5) (reverse x5))))
  32.                     )
  33.                   )
  34.                 )
  35.               )
  36.               x6
  37.             )
  38.           )
  39.         )
  40.         (entupd lw)
  41.       )
  42.     )
  43.   )
  44.  
  45.   (if
  46.     (and
  47.       (not (prompt "\nSelect objects with vertices you want to stretch - you must select window where vertices are placed - polyline must have start, middle and end vertices..."))
  48.       (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))
  49.       (not (prompt "\nNow pick boundary curve you want vertices to stretch to..."))
  50.       (setq s (ssget "_+.:E:S"))
  51.     )
  52.     (progn
  53.       (setq c (ssname s 0))
  54.       (setq sn (ssnamex ss))
  55.       (setq sn (vl-remove-if '(lambda ( x ) (= (length x) 4)) sn))
  56.       (setq sn (mapcar 'cadr (cdar sn)))
  57.       (setq sn (mapcar '(lambda ( x ) (list (car x) (cadr x))) sn))
  58.       (foreach pl (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  59.         (setq pts (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (setq enx (entget pl)))))
  60.         (setq n (length pts))
  61.         (if (< (caar pts) (car (last pts)))
  62.           (progn
  63.             (rlw pl)
  64.             (setq pts (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (setq enx (entget pl)))))
  65.           )
  66.         )
  67.         (setq ptt (vl-remove-if-not '(lambda ( x ) (and (< (apply 'min (mapcar 'car sn)) (car x) (apply 'max (mapcar 'car sn))) (< (apply 'min (mapcar 'cadr sn)) (cadr x) (apply 'max (mapcar 'cadr sn))))) pts))
  68.         (setq ip (vlax-invoke (vlax-ename->vla-object c) 'intersectwith (vlax-ename->vla-object pl) acextendnone))
  69.         (setq ip (list (car ip) (cadr ip)))
  70.         (setq k -1)
  71.         (foreach p pts
  72.           (setq k (1+ k))
  73.           (if (and (<= (1+ k) (1- (length pts))) (ptonline (nth k pts) ip (nth (1+ k) pts)))
  74.             (progn
  75.               (if (and (< (apply 'min (mapcar 'car sn)) (car (nth k pts)) (apply 'max (mapcar 'car sn))) (< (apply 'min (mapcar 'cadr sn)) (cadr (nth k pts)) (apply 'max (mapcar 'cadr sn))))
  76.                 (setq vec (mapcar '- ip (nth k pts)))
  77.                 (setq vec (mapcar '- ip (nth (1+ k) pts)))
  78.               )
  79.               (setq ptn (mapcar '(lambda ( x ) (mapcar '+ vec x)) ptt))
  80.               (if (and (< (apply 'min (mapcar 'car sn)) (car (nth k pts)) (apply 'max (mapcar 'car sn))) (< (apply 'min (mapcar 'cadr sn)) (cadr (nth k pts)) (apply 'max (mapcar 'cadr sn))))
  81.                 (setq pts (append ptn (vl-remove-if '(lambda ( x ) (vl-some '(lambda ( y ) (equal x y 1e-6)) ptt)) pts)))
  82.                 (setq pts (append (vl-remove-if '(lambda ( x ) (vl-some '(lambda ( y ) (equal x y 1e-6)) ptt)) pts) ptn))
  83.               )
  84.               (setq enx (append (reverse (member (assoc 38 enx) (reverse enx))) (apply 'append (mapcar '(lambda ( p ) (list (cons 10 p) (cons 40 0.0) (cons 41 0.0) (cons 42 0.0) (cons 91 0))) pts)) (list (list 210 0.0 0.0 1.0))))
  85.               (entupd (cdr (assoc -1 (entmod enx))))
  86.               (setq enx (entget pl))
  87.               (if (> (cdr (assoc 90 enx)) n)
  88.                 (progn
  89.                   (setq k (- (cdr (assoc 90 enx)) n))
  90.                   (setq enx (subst (cons 90 n) (assoc 90 enx) enx))
  91.                   (repeat k
  92.                     (setq enx (append (reverse (cdr (vl-member-if '(lambda ( x ) (equal (assoc 10 (reverse enx)) x 1e-6)) (reverse enx)))) (list (list 210 0.0 0.0 1.0))))
  93.                   )
  94.                   (entupd (cdr (assoc -1 (entmod enx))))
  95.                 )
  96.               )
  97.             )
  98.           )
  99.         )
  100.       )
  101.     )
  102.   )
  103.   (princ)
  104. )
  105.  

HTH.
M.R.
« Last Edit: December 13, 2023, 04:37:24 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

JGA

  • Mosquito
  • Posts: 10
Re: Stretch multiple base point polylines to different distance
« Reply #5 on: December 13, 2023, 11:49:46 AM »

(defun c:stretch-vert-curve

HTH.
M.R.

Thanks for sharing. It only seems to work with a single crossing box, multiple selections or the crossing lasso seems to fox the routine.
This is working with AutoCAD LT 2024.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Stretch multiple base point polylines to different distance
« Reply #6 on: December 13, 2023, 01:19:08 PM »
I think that reverse lwpoly isn't necessary, but I'll leave it in routine to make every lwpoly oriented the same direction...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Stretch multiple base point polylines to different distance
« Reply #7 on: December 13, 2023, 04:38:42 PM »

(defun c:stretch-vert-curve

HTH.
M.R.

Thanks for sharing. It only seems to work with a single crossing box, multiple selections or the crossing lasso seems to fox the routine.
This is working with AutoCAD LT 2024.

I think it should be fine now and with lasso selection... Thanks for feedback...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

JGA

  • Mosquito
  • Posts: 10
Re: Stretch multiple base point polylines to different distance
« Reply #8 on: December 14, 2023, 04:39:04 AM »


I think it should be fine now and with lasso selection... Thanks for feedback...

Thanks for looking at the routine. It works perfectly with a crossing window, but the lasso crossing still seems to muck up the polylines when the line is to the left of the selected alignment line. It works fine with selecting polylines to the right of the alignment line.
I presume it's a limitation of how AutoCAD works out the crossing area with the lasso.

A small characteristic is that pressing Ctrl-Z will undo the action plus one more - i.e. if the last item I did was draw a line before starting stretch-vert-curve, pressing undo would delete the line.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Stretch multiple base point polylines to different distance
« Reply #9 on: December 14, 2023, 03:40:40 PM »


I think it should be fine now and with lasso selection... Thanks for feedback...

Thanks for looking at the routine. It works perfectly with a crossing window, but the lasso crossing still seems to muck up the polylines when the line is to the left of the selected alignment line. It works fine with selecting polylines to the right of the alignment line.
I presume it's a limitation of how AutoCAD works out the crossing area with the lasso.

A small characteristic is that pressing Ctrl-Z will undo the action plus one more - i.e. if the last item I did was draw a line before starting stretch-vert-curve, pressing undo would delete the line.

On my BricsCAD it works from both sides and with lasso selection... Watch attached animated *.gif...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube