- ;;仅对水平和垂直相交直线有效 By Lisper 2013.10.01
- (defun c:tt (/ SS N E EL P1 P2 ANG L1 L2 YL XL X1 X2 L Y1 Y2)
- (setq ss (ssget '((0 . "line"))))
- (if ss
- (progn
- (repeat (setq n (sslength ss))
- (setq e (ssname ss (setq n (1- n))))
- (setq el (entget e)
- p1 (cdr (assoc 10 el))
- p2 (cdr (assoc 11 el))
- ang (angle p1 p2)
- )
- (if (or (equal 0 ang 1e-4)
- (equal pi ang 1e-4)
- )
- (setq l1 (cons e l1))
- (setq l2 (cons e l2))
- )
- )
- (setq l1 (vl-sort l1 '(lambda (a b) (< (caddr (assoc 10 (entget a))) (caddr (assoc 10 (entget b)))))) ;_ 水平
- yl (mapcar '(lambda (x) (caddr (assoc 10 (entget x)))) l1)
- l2 (vl-sort l2 '(lambda (a b) (< (cadr (assoc 10 (entget a))) (cadr (assoc 10 (entget b)))))) ;_ 垂直
- xl (mapcar '(lambda (x) (cadr (assoc 10 (entget x)))) l2)
- )
- (foreach line l1 ;_ 处理水平线
- (setq el (entget line)
- p1 (cdr (assoc 10 el))
- x1 (car p1)
- p2 (cdr (assoc 11 el))
- x2 (car p2)
- )
- (setq l (vl-sort-i xl '(lambda (a b) (< (abs (- x1 a)) (abs (- x1 b))))))
- (setq p1 (list (nth (car l) xl) (cadr p1) (caddr p1)))
- (setq l (vl-sort-i xl '(lambda (a b) (< (abs (- x2 a)) (abs (- x2 b))))))
- (setq p2 (list (nth (car l) xl) (cadr p2) (caddr p2)))
- (setq el (subst (cons 10 p1) (assoc 10 el) el)
- el (subst (cons 11 p2) (assoc 11 el) el)
- )
- (entmod el)
- )
- (foreach line l2 ;_ 处理垂直线
- (setq el (entget line)
- p1 (cdr (assoc 10 el))
- y1 (cadr p1)
- p2 (cdr (assoc 11 el))
- y2 (cadr p2)
- )
- (setq l (vl-sort-i yl '(lambda (a b) (< (abs (- y1 a)) (abs (- y1 b))))))
- (setq p1 (list (car p1) (nth (car l) yl) (caddr p1)))
- (setq l (vl-sort-i yl '(lambda (a b) (< (abs (- y2 a)) (abs (- y2 b))))))
- (setq p2 (list (car p2) (nth (car l) yl) (caddr p2)))
- (setq el (subst (cons 10 p1) (assoc 10 el) el)
- el (subst (cons 11 p2) (assoc 11 el) el)
- )
- (entmod el)
- )
- )
- )
- (princ)
- )
|