;程序中用的都是autolisp函数,没有加入任何visuallisp函数,实践足可证明autolisp的强大之处。
(defun interss (ss) ;;选择集求交点子程序
(setq len (sslength ss) n1 0 pts nil)
(repeat (- len 1)
(setq ent (entget (ssname ss n1)) p nil)
(foreach x ent (if (member (car x) '(10 11)) (setq p (cons (cdr x) p))))
(setq p1 (car p) p2 (cadr p) n2 (1+ n1)) ;求一条线段的两个端点
(repeat (- len n2)
(setq ent (entget (ssname ss n2)) p nil)
(foreach x ent (if (member (car x) '(10 11)) (setq p (cons (cdr x) p))))
(setq p3 (car p) p4 (cadr p)) ;求另一线段的两个端点
(if (setq ipts (inters p1 p2 p3 p4)) (setq pts (cons ipts pts))) ;求两条线段的交点,并集合
(setq n2 (1+ n2)))
(setq n1 (1+ n1)))
pts)
(defun c:tt () ;;一次性将所选线段从交点处打断,仅限于直线和多义线
(setq ss (ssget '((0 . "*line"))))
(if (and ss (interss ss)) (progn
(while t ;结合exit函数
(setq len (sslength ss) n 0)
(repeat len
(foreach x pts
(if (ssmemb (ssname ss n) (ssget "c" x x)) (progn
(command "break" (ssname ss n) x x)
(ssadd (entlast) ss))))
(setq n (+ n 1)))
(if (= (sslength ss) len) (exit))))) ;如果ss个数不增加,退出循环。
(princ))