Need an AutoLISP to draw separate polylines from a master point to multiple secondary points

Need an AutoLISP to draw separate polylines from a master point to multiple secondary points

zjgamesandstuff
Explorer Explorer
1,257 Views
8 Replies
Message 1 of 9

Need an AutoLISP to draw separate polylines from a master point to multiple secondary points

zjgamesandstuff
Explorer
Explorer

Like the title suggests, I am in a pinch and at my wits end trying to create an AutoLISP to draw separate polylines from a master point to multiple secondary points.

Here is an example of how the points will typically be arranged with the master point above where the secondary points are located:

zjgamesandstuff_1-1652912046181.png

 

Essentially, I need to be able to choose the master point, where the Polyline will originate from, and then have it automatically draw separate polylines from the master point to all selected secondary points. So in this example there would be 4 separate polylines.

Here is where it gets tricky. I need the polylines to first draw south until it becomes perpendicular with the secondary points, and then make a 90° turn and draw until it intersects the selected points. See the example below:

zjgamesandstuff_2-1652912376470.png

 

If anyone could help me out or at least give me some direction on how to create this autoLISP I would greatly appreciate it!

 

0 Likes
Accepted solutions (2)
1,258 Views
8 Replies
Replies (8)
Message 2 of 9

3wood
Advisor
Advisor

You can try the code below.

LPT.gif

;;; LPT.lsp by 3wood 2022.5.19.
;;; Link master point with secondary points with polyline in orthogonal mode

;Make a LwPolyline from a given list of WCS cooridinates
(defun LPT_LWPLINE_Make (LST)
  (foreach n LST
    (entmake (apply
	       (function append)
	       (cons (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length n))'(70 . 0))
		     (mapcar (function list)
			     (mapcar '(lambda (x) (cons 10 x)) n)
			     ))))
    )
  )

(defun C:LPT (/ e0 n1 P0 P1 ss1)
  (if (and (setq e0 (car (entsel "\nSelect the master point: ")))
	   (setq P0 (cdr (assoc 10 (entget e0))))
	   (princ "\nSelect secondary points: ")
	   (setq ss1 (ssget))
	   (if (> (sslength (if (ssmemb e0 ss1) (ssdel e0 ss1))) 0) T nil)
	   (setq n1 0)
	   )
    (repeat (sslength ss1)
      (setq P1 (cdr (assoc 10 (entget (ssname ss1 n1)))))
      (if (equal (cadr P0) (cadr P1))
	(LPT_LWPLINE_Make (list (list P0 P1)))
	(LPT_LWPLINE_Make (list (list P0 (list (car P0) (cadr P1)) P1)))
	)
      (setq n1 (1+ n1))
      )
    )
  )

 

 

Message 3 of 9

Kent1Cooper
Consultant
Consultant

Here's my take on it:

 

(defun C:PMP2MP (/ mp tpss n tp) ; = Polylines from Master Point {to} Multiple Points
  (if
    (and
      (not (prompt "\nFor the Master Point,")) (setq mp (ssget "_:S+." '((0 . "POINT"))))
      (not (prompt "\nand for the target Point(s),")) (setq tpss (ssget '((0 . "POINT"))))
    ); and
    (progn ; then
      (ssdel (setq mp (ssname mp 0)) tpss); in case selected with others
      (setq mp (cdr (assoc 10 (entget mp))))
      (repeat (setq n (sslength tpss))
        (setq tp (cdr (assoc 10 (entget (ssname tpss (setq n (1- n)))))))
        (command "_.pline" "_non" mp "_non" (list (car mp) (cadr tp)) "_non" tp "")
      ); repeat
    ); progn
    (prompt "\nNo Point(s) selected."); else
  ); if
  (princ)
)

 

Kent Cooper, AIA
Message 4 of 9

calderg1000
Mentor
Mentor
Accepted solution

Regards @zjgamesandstuff 

Try this code

(defun c:P90( / p pb s i ps psn pp )
  (setq p (entget(car(entsel"\nPick Master Point : "))))
  (setq pb (cdr(assoc 10 p)))
  (princ "\nSelect Secondary Points: ")
  (setq s(ssget'((0 . "point"))))
  (repeat(setq i(sslength s))
  (setq ps(entget(ssname s (setq i(1- i))))
        psn(cdr(assoc 10 ps))
        pp(list (car pb) (cadr psn) 0.))
    (setq lst(list pb pp psn))
        (entmake (append(list
                   (cons 0 "lwpolyline")
                   (cons 100 "AcDbEntity")
                   (cons 100 "AcDbPolyline")
                   (cons 90 3)
                   (cons 70 0))
                   (mapcar '(lambda (x) (cons 10 x)) lst)
                   )
                 )
         )
        )

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.

Message 5 of 9

zjgamesandstuff
Explorer
Explorer

You are all beautiful people, thank you so much for your help on this!

0 Likes
Message 6 of 9

zjgamesandstuff
Explorer
Explorer

Would anyone be able to help me out with editing @calderg1000 lisp to do the following?: 

I am trying to figure out how to take this code and make the polyline get  drawn horizontal first and then drawn vertical. For example:
This is how it is currently being drawn

zjgamesandstuff_0-1664899961076.png

 

 

But I need the red line to follow along the yellow dashed line and then get drawn up to the green points like this:

zjgamesandstuff_1-1664900055982.png

 

I understand I can just select the green point and then the white point to have the line drawn correctly, but I need to alter the code to start from the white point, as that is the master point and there can be dozens of secondary, green, points.

 

Any help  or advice would be greatly appreciated

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

You can just switch the objects from which it is taking the X and Y coordinates for the intermediate point:

        pp(list (car psn) (cadr pb) 0.))
Kent Cooper, AIA
0 Likes
Message 8 of 9

zjgamesandstuff
Explorer
Explorer

Thank you so much!! In case it wasn't obvious, I am very new to autolisps and I am certainly not a programmer lol.

0 Likes
Message 9 of 9

NoelN.
Contributor
Contributor

Hi there, this Lisp is amazing but can I ask a question on this? Is there a way on this process on choosing the base point that all the polyline is coming from, to add a reference line like the yellow polyline on the image attached so that you it won't just create is only horizontal or vertical.

The reason I ask is because I'm an Telecom Engineer and design FTTH construction prints and if this is possible to create on the ask above then that would save my life on production. thank you in an advance.

0 Likes