Another one for fun
(defun c:foo (/ _dxf _sl a b c e p s x)
;; RJP » 2019-01-10
(defun _sl (s) (cond ((= 'pickset (type s)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))))
(defun _dxf (c e) (cdr (assoc c (entget e))))
(cond
((setq s (_sl (ssget)))
(foreach x s
(if (wcmatch (_dxf 0 x) "CIRCLE,INSERT,POINT")
(setq b (cons (_dxf 10 x) b))
(and (= 'real (type (vl-catch-all-apply 'vlax-curve-getendparam (list x))))
(setq a (cons x a))
)
)
)
(and a
b
(foreach p b
(setq c
(mapcar '(lambda (x)
(list (setq c (vlax-curve-getclosestpointto x p)) (distance p c) (_dxf 8 x))
)
a
)
)
(setq c (car (vl-sort c '(lambda (r j) (< (cadr r) (cadr j))))))
(if (not (equal 0 (cadr c) 1e-3))
(progn (setq
e (entmakex (list '(0 . "line") (cons 10 p) (cons 11 (car c)) (cons 8 (caddr c))))
)
;; This line below creates the right example comment out to get left
(setq a (cons e a))
)
)
)
)
)
)
(princ)
)