Author Topic: Electrical Lisp - connect objects  (Read 1058 times)

0 Members and 1 Guest are viewing this topic.

jtm2020hyo

  • Newt
  • Posts: 198
Electrical Lisp - connect objects
« on: April 19, 2020, 12:16:13 AM »
I was lucky, I found an awesome lisp.

the attached code connects 2 points passing by polyline run.





Code: [Select]
(vl-load-com)

(defun c:Connect2Points ( / en ex e1 e2 el p1 q1 p2 q2 pe ps la)

  (if (and (setq *c2p-en* (cond ((car (entsel (strcat "\nSelect axis polyline " (if *c2p-en* " <last>" ": ")))))
(*c2p-en*)))
   (= "LWPOLYLINE" (cdr (assoc 0 (entget *c2p-en*))))
   (setq p1 (getpoint "\nSpecify 1st point: "))
   (setq p1 (trans p1 1 0))
   (setq q1 (vlax-curve-getClosestPointTo *c2p-en* p1))
   (setq p2 (getpoint "\nSpecify 2nd point: "))
   (setq p2 (trans p2 1 0))
   (setq q2 (vlax-curve-getClosestPointTo *c2p-en* p2))
   (setq ps (vlax-curve-getStartPoint *c2p-en*))
   (setq pe (vlax-curve-getEndPoint *c2p-en*))
   )
    (progn
      (setq la "cable")  ; set cable layer name
      (command "_.LAYER" "_New" la "_Color" 2 la "")                    ; set its color..
      (setq en (entmakex (append (entget *c2p-en*)
(list (cons 8 la)))))
      (setq el (entlast))
      (and (not (equal q1 pe 1e-6))
   (not (equal q1 ps 1e-6))
   (vl-cmdf "_.BREAK" en "_none" (trans q1 0 1) "_none" (trans q1 0 1))
   (not (equal el (entlast)))
   (setq ex (entlast))
   )
      (if (equal q2 (vlax-curve-getClosestPointTo en q2) 1e-6)
(if ex (entdel ex))
(progn
  (entdel en)
  (setq en ex)))
      (setq ex nil
    el (entlast))
      (and (not (equal q2 pe 1e-6))
   (not (equal q2 ps 1e-6))
   (vl-cmdf "_.BREAK" en "_none" (trans q2 0 1) "_none" (trans q2 0 1))
   (not (equal el (entlast)))
   (setq ex (entlast))
   )
      (if (and (or (equal q1 (vlax-curve-getStartPoint en) 1e-6)
   (equal q1 (vlax-curve-getEndPoint en) 1e-6))
       (or (equal q2 (vlax-curve-getStartPoint en) 1e-6)
   (equal q2 (vlax-curve-getEndPoint en) 1e-6)))
(if ex (entdel ex))
(progn
  (entdel en)
  (setq en ex)))
      (setq e1 (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 q1) (cons 8 la)))
    e2 (entmakex (list (cons 0 "LINE") (cons 10 p2) (cons 11 q2) (cons 8 la))))
      (initcommandversion)
      (command "_.JOIN" e1 en e2 "")
      ))
  (princ)
)


video example:

https://knowledge.autodesk.com/community/screencast/4a74ff92-5303-412f-8c4b-5e9ecb152c14




... My request for help is to change the lisp to allow select multiple regular and dynamic blocks and connect to the selected point (multiple blocks to one point) passing for selected polyline run, as show in the video.
« Last Edit: April 19, 2020, 12:24:01 AM by jtm2020hyo »