@Tolearnlisp wrote:
Hi BeeKeeCZ,
Great Code and I appreciate your effort.
I forgot to mention that there are cases that the squares and circles being selected vertically. After trying the code in this case, the wire are crossing even I select it in the same direction using window. It works when I select the square&circles individually. I hope you can still improve the current code. Thank you.
See attached drawing for your reference.
OK, the issue fixed! See how it works HERE
(defun c:LineConnect (/ ss ssp ssc lsp lsc d d0 dir)
(if (and (princ "\nSelect SQUAREs and CIRCLEs to connect: ")
(setq ss (ssget '((-4 . "<OR")
(0 . "CIRCLE")
(-4 . "<AND") (0 . "LWPOLYLINE") (90 . 4) (-4 . "AND>")
(-4 . "OR>"))))
(setq ssp (acet-ss-ssget-filter ss '((0 . "LWPOLYLINE"))))
(setq ssc (acet-ss-ssget-filter ss '((0 . "CIRCLE"))))
(setq lsp (mapcar '(lambda (e) (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget e))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssp)))))
(setq lsp (mapcar '(lambda (x) (trans (mapcar '/ (mapcar '+ (cdar x) (cdaddr x)) '(2 2)) 0 1)) lsp))
(setq lsc (mapcar '(lambda (e) (trans (cdr (assoc 10 (entget e))) 0 1)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssc)))))
(setq d (abs (/ (- (apply 'max (mapcar 'car lsp)) (apply 'min (mapcar 'car lsp))) ;xmax-xmin
(if (zerop (setq d0 (- (apply 'max (mapcar 'cadr lsp)) (apply 'min (mapcar 'cadr lsp))))) ;ymax-ymin
0.001
d0))))
)
(progn
(if (< 0.2 d 5)
(progn
(initget "Horizontal Vertical")
(setq dir (getkword "\nChoose an option [Horizontal/Vertical]: "))))
(if (or (= dir "Horizontal")
(> d 5))
(setq lsp (vl-sort lsp '(lambda (p q) (< (car p) (car q))))
lsc (vl-sort lsc '(lambda (p q) (< (car p) (car q)))))
(setq lsp (vl-sort lsp '(lambda (p q) (< (cadr p) (cadr q))))
lsc (vl-sort lsc '(lambda (p q) (< (cadr p) (cadr q))))))
(mapcar '(lambda (p1 p2)
(entmakex (list (cons 0 "LINE")
(cons 10 p1)
(cons 11 p2)
(cons 8 "wire"))))
lsp lsc)))
(princ)
)
PS. It was really not an issue - you obviously have no idea what the Fence type of selection is. So read about it HERE and HERE in help.
But with the upper code you can select squares and circle anyway you want. Just don't combine horizontal with vertical or upper and lower. See the video linked above.