- 积分
- 1156
- 明经币
- 个
- 注册时间
- 2015-11-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2017-11-14 17:01:57
|
显示全部楼层
(defun c:scf(/ dxf tang chg_ent on_ent undup os 2pi sline sarc scircle n ss ent pmt)
(setvar "cmdecho" 0)
(PRINC "\n刪除重複功能")
(PRINC)
(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)
(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) "ARC") (ssadd ent sarc))
((= (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" 695)
(PRINC "\n所選地方 刪除重複 完成")
(PRINC)
) |
|