;;消除重复线条 (defun c:XCF(/ dxf tang chg_ent on_ent undup os 2pi sline sarc scircle n ss ent pmt) (defun dxf(ent i) (cdr (assoc i (entget ent))) ) (defun tang(ang sty) (rem (+ 2pi ang) sty) ) (defun chg_ent(ent i pt / en) (setq en (entget ent) en (subst (cons i pt) (assoc i en) en)) (entmod en) ) (defun on_ent(a a1 a2 sty) (if (= sty "直线") (equal (+ (distance a1 a) (distance a a2)) (distance a1 a2) 0.01) (if (> a2 a1) (>= a2 a a1) (or (<= a a2) (>= a a1))) ) ) (defun undup(s sty / nm m ss ent1 spt1 ept1 cpt1 r1 ent2 spt2 ept2 cpt2 r2) (setq n -1 nm 0) (if (= sty "圆") (repeat (sslength s) (setq ent1 (ssname s (setq n (1+ n)))) (if (entget ent1) (progn (setq cpt1 (dxf ent1 10) r1 (dxf ent1 40)) (if (setq ss (ssget "x" (list (cons 0 "circle") (cons 10 cpt1) (cons 40 r1)))) (progn (ssdel ent1 ss) (setq m -1) (repeat (sslength ss) (setq ent (ssname ss (setq m (1+ m)))) (if (not (ssmemb ent s)) (progn (ssdel ent ss) (setq m (1- m)) ) ) ) (command "_.erase" ss "") (setq nm (+ nm (sslength ss))) ) ) ) ) ) (repeat (sslength s) (setq ent1 (ssname s (setq n (1+ n)))) (if (entget ent1) (progn (if (= sty "直线") (setq spt1 (dxf ent1 10) ept1 (dxf ent1 11)) (setq spt1 (tang (dxf ent1 50) 2pi) ept1 (tang (dxf ent1 51) 2pi) cpt1 (dxf ent1 10) r1 (dxf ent1 40) ) ) (if (setq ss (if (= sty "直线") (ssget "cp" (list (polar spt1 (angle ept1 spt1) 0.1) (polar ept1 (- (angle spt1 ept1) (/ pi 4)) 0.15) (polar ept1 (+ (angle spt1 ept1) (/ pi 4)) 0.15) ) '((0 . "line")) ) (ssget "x" (list (cons 0 "arc") (cons 10 cpt1) (cons 40 r1))) ) ) (progn (ssdel ent1 ss) (setq m -1) (repeat (sslength ss) (setq ent (ssname ss (setq m (1+ m)))) (if (not (ssmemb ent s)) (progn (ssdel ent ss) (setq m (1- m)) ) ) ) (setq m -1) (repeat (sslength ss) (setq ent2 (ssname ss (setq m (1+ m)))) (if (= sty "直线") (setq spt2 (dxf ent2 10) ept2 (dxf ent2 11) ) setq spt2 (tang (dxf ent2 50) 2pi) ept2 (tang (dxf ent2 51) 2pi) cpt2 (dxf ent2 10) r2 (dxf ent2 40) ) ) (cond ((and (on_ent spt2 spt1 ept1 sty) (on_ent ept2 spt1 ept1 sty)) (entdel ent2) ) ((and (on_ent spt1 spt2 ept2 sty) (on_ent ept1 spt2 ept2 sty)) (entdel ent1) (setq ent1 ent2 spt1 spt2 ept1 ept2) (if (= sty "圆弧") (setq cpt1 cpt2 r1 r2) ) ) ((and (if (= sty "直线") (equal (tang (angle spt1 ept1) pi) (tang (angle spt2 ept2) pi) 0.001) T ) (or (on_ent spt2 spt1 ept1 sty) (on_ent ept2 spt1 ept1 sty)) ) (entdel ent2) (if (= sty "直线") (progn (if (on_ent spt2 spt1 ept1 sty) (setq spt2 ept2) ) (if (> (distance spt1 spt2) (distance ept1 spt2)) (progn (chg_ent ent1 11 spt2) (setq ept1 spt2)) (progn (chg_ent ent1 10 spt2) (setq spt1 spt2)) ) ) (if (on_ent spt2 spt1 ept1 sty) (progn (chg_ent ent1 51 ept2) (setq ept1 ept2)) (progn (chg_ent ent1 50 spt2) (setq spt1 spt2)) ) ) ) (T (setq nm (1- nm))) ) (setq nm (1+ nm)) ) ) ) ) ) ) ) (prompt (strcat "选到" (itoa (sslength s)) "个" sty "消去" (itoa nm) "个!")) ) (command "_.undo" "_be") (command "_.ucs" "") (setq os (getvar "osmode") 2pi (* 2 pi) sline (ssadd) sarc (ssadd) scircle (ssadd) n -1 ) (setvar "cmdecho" 0) (setvar "osmode" 0) (PRINC "\n消除重复线功能")(PRINC) (prompt "\n→请选择直线、圆弧或圆:") (if (setq ss (ssget '((0 . "line,arc,circle")))) (progn (prompt "\n→正在消除重复线条,请稍候...") (prompt "\n") (repeat (sslength ss) (setq ent (ssname ss (setq n (1+ n)))) (cond ((= (dxf ent 0) "LINE") (ssadd ent sline)) ((= (dxf ent 0) "CIRCLE") (ssadd ent scircle)) ) ) ) ) (if (> (sslength sline) 1) (progn (undup sline "直线") (setq pmt T))) (if (> (sslength sarc) 1) (progn (undup sarc "圆弧") (setq pmt T))) (if (> (sslength scircle) 1) (progn (undup scircle "圆") (setq pmt T))) (if (and ss (not pmt)) (prompt "\n→没有重复实体!")) (setvar "osmode" os) (command "_.undo" "_e") (princ) (PRINC "\n所选地方→消除重复线完成!")(PRINC))
|