将距离最近的圆心用绿色直线连接。

- (defun c:CircleLink (/ ss i j lst ent pt minDist minIndex line)
- (vl-load-com)
- (princ "\n请框选圆对象: ")
- (if (setq ss (ssget '((0 . "CIRCLE"))))
- (progn
- ; 收集圆心坐标
- (setq i 0 lst '())
- (repeat (sslength ss)
- (setq ent (entget (ssname ss i)))
- (setq lst (cons (cdr (assoc 10 ent)) lst))
- (setq i (1+ i))
- )
-
- ; 计算并连接最近圆心
- (setq i 0)
- (while (< i (length lst))
- (setq minDist 1e308 minIndex -1 pt (nth i lst))
-
- ; 查找最近圆心
- (setq j 0)
- (while (< j (length lst))
- (if (/= i j)
- (progn
- (setq dist (distance pt (nth j lst)))
- (if (< dist minDist)
- (setq minDist dist minIndex j)
- )
- )
- )
- (setq j (1+ j))
- )
-
- ; 绘制连接线
- (if (>= minIndex 0)
- (entmake (list '(0 . "LINE")
- (cons 10 pt)
- (cons 11 (nth minIndex lst))
- '(62 . 3))) ; 绿色连线
- )
- (setq i (1+ i))
- )
- )
- (princ "\n未选择到圆对象!")
- )
- (princ)
- )
|