(defun c:overkill(/ lst)(acet-error-init (list '("cmdecho"0)T))(if(setq lst(acet-overkill-ui nil))(acet-overkill2 lst))(acet-error-restore))(defun c:-overkill(/ lst)(acet-error-init (list '("cmdecho"0)T))(if(setq lst(acet-overkill-ui T))(acet-overkill2 lst))(acet-error-restore))(defun acet-overkill-ui(cmdline / ss lst)(if(and(setq ss(ssget"_:l"))(setq ss(car(acet-ss-filter(list ss nil T)))))(progn(princ"\n")(if(or cmdline(= 4(logand 4(getvar"cmdactive")))(= 0(getvar"cmddia")))(setq lst(acet-overkill-ui-cmd))(setq lst(acet-overkill-ui-dlg)))(if lst(setq lst(cons ss lst))))))(defun acet-overkill-ui-cmd(/ ans)(setq ans T)(while ans(acet-overkill-print-modes)(initget"Ignore Fuzz Plines parTial Endtoend")(setq ans(getkword"\n输入改变的选项 [忽略(I)/毛状(F)/多段线(P)/不完全(T)/端到端(E)] <完成>: "))(cond((= ans"Ignore")(acet-overkill-ui-cmd-ignore))((= ans"Fuzz")(acet-overkill-ui-cmd-fuz))((= ans"Plines")(acet-overkill-ui-cmd-plines))((= ans"parTial")(acet-overkill-ui-cmd-partial))
((= ans"Endtoend")(acet-overkill-ui-cmd-endtoend))))(list(max(acet-overkill-fuz-get)1.0e-08)(acet-overkill-ignore-get)(acet-overkill-no-plines-get)(acet-overkill-no-partial-get)(acet-overkill-no-endtoend-get)))(defun acet-overkill-ui-cmd-fuz(/ def fuz ans)(setq def(acet-overkill-fuz-get))(if(not def)(setq def 0.000001))(initget 4)(setq ans(getdist(acet-str-format"\n指定数量比较的毛状<%1>: "(acet-rtos2 def))))(if(not ans)(setq ans def))(acet-overkill-fuz-set ans)ans )(defun acet-overkill-ui-cmd-ignore(/ def fuz ans lst a x anslst lst2 lst3 n ignore)(setq ignore(acet-overkill-ignore-get))(acet-overkill-print-ignore)(setq lst '((8"LAYER")(6"LTYPE")(62"COLOR")(370"LWEIGHT")(390"PLOTSTYLE")))(foreach x lst(setq lst2(cons(cadr x)lst2)))(setq lst2(cons"."lst2)lst2(reverse lst2))(princ"\n指定当比较对象时忽略的属性... ") (setq ans(acet-ui-m-get-names (list nil	"\n[图层,线条类型,颜色,线条宽度,打印风格, * (表示全部)] 或者\".\"表示没有<默认>: "lst2	)))(if ans(progn(setq lst(mapcar 'reverse lst)
lst2 nil)(foreach x ans(if(setq a(assoc x lst))(setq lst2(cons(cadr a)lst2))))(setq lst2(reverse lst2))(acet-overkill-ignore-set lst2)))(acet-overkill-ignore-get))(defun acet-overkill-ui-cmd-plines(/ def ans a)(setq def(acet-overkill-no-plines-get))(if(= def 1)(setq def"No")(setq def"Yes"))(initget"Yes No")(setq ans(getkword(acet-str-format"\n多段线中优化段<%1>: "def)))(if(not ans)(setq ans def))(if(= ans"No")(progn(acet-overkill-no-plines-set T)(setq a T))(acet-overkill-no-plines-set nil))a)(defun acet-overkill-ui-cmd-partial(/ def ans a)(setq def(acet-overkill-no-partial-get))(if(= def 1)(setq def"No")(setq def"Yes"))(initget"Yes No")(setq ans(getkword(acet-str-format"\n合并部分重叠的交叉线性对象 <%1>: "def)))(if(not ans)(setq ans def))(if(= ans"No")(progn(acet-overkill-no-partial-set T)(setq a T))(acet-overkill-no-partial-set nil))a)(defun acet-overkill-ui-cmd-endtoend(/ def ans a)(setq def(acet-overkill-no-endtoend-get))(if(= def 1)(setq def"No")(setq def"Yes"))(initget"Yes No")
(setq ans(getkword(acet-str-format"\n当对齐到端到端是合并交叉线性对象<%1>: "def)))(if(not ans)(setq ans def))(if(= ans"No")(progn(acet-overkill-no-endtoend-set T)(setq a T))(acet-overkill-no-endtoend-set nil))a)(defun acet-overkill-print-ignore(/ ignore lst a x)(setq ignore(acet-overkill-ignore-get))(setq lst '((8"Layer")(6"Linetype")(62"Color")(370"Lineweight")(390"Plotstyle")))(if ignore(princ"\n忽略=")(princ"\n忽略=没有"))(foreach x ignore(if a(princ","))(if(setq a(assoc x lst))(princ(cadr a)))))(defun acet-overkill-print-modes(/ fuz ignore no-plines no-partial no-endtoend x a lst)(setq fuz(acet-overkill-fuz-get)no-plines(acet-overkill-no-plines-get)no-partial(acet-overkill-no-partial-get)no-endtoend(acet-overkill-no-endtoend-get))(acet-overkill-print-ignore)(princ"\n")(princ(strcat"毛状="(acet-rtos2 fuz)))(if(not no-plines)		(princ", 优化多段线=是")(princ", 优化多段线=否"))(if(not no-partial)(princ", 合并部分重叠=是")(princ", 合并部分重叠=否"))(if(not no-endtoend)
(princ", 合并端到端=是")(princ", 合并端到端=否")))(defun acet-overkill-ui-dlg(/ ignore checkit lst flag iv fuz)(setq ignore(acet-overkill-ignore-get))(if(>(setq iv(load_dialog"overkill"))0)(progn(if(new_dialog"overkill"iv)(progn(defun checkit(/ ignore fuz lst no-plines no-partial no-endtoend)(if(=(get_tile"layer")"1")(setq ignore(cons 8 ignore)))(if(=(get_tile"linetype")"1")(setq ignore(cons 6 ignore)))(if(=(get_tile"color")"1")(setq ignore(cons 62 ignore)))(if(=(get_tile"lineweight")"1")(setq ignore(cons 370 ignore)))(if(=(get_tile"plotstyle")"1")(setq ignore(cons 390 ignore)))(if(=(get_tile"plines")"0")(setq no-plines T))(if(=(get_tile"partial")"0")(setq no-partial T))(if(=(get_tile"endtoend")"0")(setq no-endtoend T))(setq fuz(get_tile"fuz"))(if(or(not(distof fuz))(<(distof fuz)0.0))(set_tile"error""Invalid. Fuzz value must be numeric and non-negative.")(setq lst(list(distof fuz)ignore no-plines no-partial no-endtoend)))lst)(if(member 8 ignore)(set_tile"layer""1")(set_tile"layer""0")
)(if(member 6 ignore)(set_tile"linetype""1")(set_tile"linetype""0"))(if(member 62 ignore)(set_tile"color""1")(set_tile"color""0"))(if(member 370 ignore)(set_tile"lineweight""1")(set_tile"lineweight""0"))(if(member 390 ignore)(set_tile"plotstyle""1")(set_tile"plotstyle""0"))(set_tile"fuz"(acet-rtos2(acet-overkill-fuz-get)))(if(acet-overkill-no-plines-get)(set_tile"plines""0")(set_tile"plines""1"))(if(acet-overkill-no-partial-get)(set_tile"partial""0")(set_tile"partial""1"))(if(acet-overkill-no-endtoend-get)(set_tile"endtoend""0")(set_tile"endtoend""1"))(action_tile"accept""(if (setq lst (checkit)) (done_dialog 1))")(action_tile"cancel""(done_dialog 0)")(action_tile"help""(acet-help \"OVERKILL\")")(setq flag(start_dialog))(if(= flag 1)(progn(acet-overkill-fuz-set(nth 0 lst))(acet-overkill-ignore-set(nth 1 lst))(acet-overkill-no-plines-set(nth 2 lst))(acet-overkill-no-partial-set(nth 3 lst))(acet-overkill-no-endtoend-set(nth 4 lst))(setq lst(list(max(nth 0 lst)1.0e-08)(nth 1 lst)
(nth 2 lst)(nth 3 lst)(nth 4 lst))))))(alert"不能显示对话框"))(unload_dialog iv))(alert"不能装载对话框"))(if(= flag 1)(acet-acad-refresh))lst)(defun acet-overkill-ignore-get(/ lst)(setq lst(acet-getvar(list"ACET-OVERKILL-IGNORE"6)))(if(and lst(/= lst""))(setq lst(acet-str-to-list","lst)lst(mapcar 'atoi lst))(setq lst nil))lst)(defun acet-overkill-ignore-set(ignore / gcode a)(setq a"")(foreach gcode ignore(setq a(strcat a","(itoa gcode))))(if(/= a"")(setq a(substr a 2)))(acet-setvar(list"ACET-OVERKILL-IGNORE"a 6)))(defun acet-overkill-fuz-get(/ fuz)(setq fuz(acet-getvar '("ACET-OVERKILL-FUZZ"1)))(if(not fuz)(setq fuz 0.000001))fuz)(defun acet-overkill-fuz-set(fuz /)(acet-setvar(list"ACET-OVERKILL-FUZZ"fuz 1)))(defun acet-overkill-no-plines-get(/ no-pline)(setq no-pline(acet-getvar '("ACET-OVERKILL-NO-PLINES")))(if(/= no-pline 1)(setq no-pline nil))no-pline)(defun acet-overkill-no-plines-set(no-pline /)(if no-pline(acet-setvar(list"ACET-OVERKILL-NO-PLINES"1 3))
(acet-setvar(list"ACET-OVERKILL-NO-PLINES"0 3))))(defun acet-overkill-no-partial-get(/ no-partial)(setq no-partial(acet-getvar '("ACET-OVERKILL-NO-PARTIAL")))(if(/= no-partial 1)(setq no-partial nil))no-partial)(defun acet-overkill-no-partial-set(no-partial /)(if no-partial(acet-setvar(list"ACET-OVERKILL-NO-PARTIAL"1 3))(acet-setvar(list"ACET-OVERKILL-NO-PARTIAL"0 3))))(defun acet-overkill-no-endtoend-get(/ no-endtoend)(setq no-endtoend(acet-getvar '("ACET-OVERKILL-NO-ENDTOEND")))(if(/= no-endtoend 1)(setq no-endtoend nil))no-endtoend)(defun acet-overkill-no-endtoend-set(no-endtoend /)(if no-endtoend(acet-setvar(list"ACET-OVERKILL-NO-ENDTOEND"1 3))(acet-setvar(list"ACET-OVERKILL-NO-ENDTOEND"0 3))))(defun acet-overkill(alst)(acet-overkill2 alst))(defun acet-overkill-resolve-lines(lst ss2 fuz no-partial no-endtoend /)(acet-overkill-resolve-arcs2 lst ss2 fuz no-partial no-endtoend))(defun acet-overkill-resolve-arcs(lst ss2 fuz no-partial no-endtoend /)
(acet-overkill-resolve-arcs2 lst ss2 fuz no-partial no-endtoend))(defun acet-overkill-line-data(e1 fuz genprops /)(acet-overkill-line-data2 e1 fuz genprops))(defun acet-overkill-gen-prop-get(e1 genprops /)(acet-overkill-gen-prop-get2 e1 genprops))(defun acet-rtos(val)(acet-rtos2 val))(defun acet-overkill-ss->primitives(ss fuz ignore)(SETVAR"CMDECHO"0)(acet-overkill-ss->primitives2 ss fuz ignore))(defun acet-overkill2(alst / lst ss fuz ignore no-plines no-partial no-EndtoEnd ss2 n na plst na2 vlst j k)(setq lst '(ss fuz ignore no-plines no-partial no-EndtoEnd))(setq n 0)(repeat(min(length alst)(length lst))(set(nth n lst)(nth n alst))(setq n(+ n 1)))(setq lst nil)(acet-sysvar-set  '("highlight"0 "ucsicon"0 "pickstyle"0 "osmode"0))(if(not no-plines)(progn(setq plst(acet-plines-explode ss)ss(car plst)			 plst(cadr plst)			)))(setq ss2(acet-ss-remove-dups ss fuz ignore)ss(car ss2)ss2(cadr ss2))(if ss2(progn(princ(acet-str-format"\n删除%1个重复。\n"(itoa(sslength ss2)))))(setq ss2(ssadd)))
(if(not(and no-partial	 no-endtoend))(progn(setq vlst(acet-overkill-ss->primitives2 ss 0.0000001 ignore)j 0)))(acet-ui-progress-init"Optimizing objects"(length vlst))(setq n 1)(foreach lst vlst(if(>(length lst)2)(progn(if(= 0(car(car lst)))(setq k(acet-overkill-resolve-lines2 lst ss2 fuz no-partial no-endtoend))(setq k(acet-overkill-resolve-arcs2 lst ss2 fuz no-partial no-endtoend)))(setq ss2(cadr k)k(car k)j(+ j k))(princ"                                                      ")(princ"\r")(princ(acet-str-format"删除%1个对象。"(itoa j)))))(acet-ui-progress-safe n)(setq n(+ n 1)))(acet-ui-progress-done)(setq na(entlast))(if(and ss2(>(sslength ss2)0))(acet-ss-entdel ss2))(if plst(acet-plines-rebuild plst))(if(and ss2(>(sslength ss2)0))(progn(acet-ss-entdel ss2)				(acet-safe-command T T(list"_.erase"ss2"")))(acet-ss-clear-prev))(acet-sysvar-restore)(princ"\n")ss2)(defun acet-overkill-resolve-lines2(lst ss2 fuz no-partial no-endtoend /  index m m2 n x na na2 p1 p2 p3 p4 mod j a b e1)
(setq a(car lst)lst(cdr lst)m(nth 1 a)	 m2(nth 3 a)	)(cond(m(setq index 0))	(m2(setq index 1))	(T(setq index 2)))(setq lst(mapcar '(lambda(x / a b)(if(<(nth index(car x))(nth index(cadr x)))(setq a(car x)b(cadr x))(setq b(car x)a(cadr x)))(list a b(caddr x)))lst)lst(vl-sort lst '(lambda(a b)(<(nth index(car a))(nth index(car b)))))x(car lst)p1(car x)p2(cadr x)na(caddr x)j 0)(setq n 1)(repeat(-(length lst)1)(setq x(nth n lst)p3(car x)p4(cadr x)na2(caddr x))(cond((equal(nth index p3)(nth index p2)fuz)(if(not no-endtoend)(progn(if(>(nth index p4)(nth index p2))(setq p2 p4 mod T))(setq ss2(ssadd na2 ss2))(setq j(+ j 1)))))((<(nth index p3)(nth index p2))(if(not no-partial)(progn(if(>(nth index p4)(nth index p2))(setq p2 p4 mod T))(setq ss2(ssadd na2 ss2))(setq j(+ j 1)))))(T(if mod(progn(setq e1(entget na)e1(subst(cons 10 p1)(assoc 10 e1)e1)e1(subst(cons 11 p2)(assoc 11 e1)e1))(entmod e1)))(setq p1 p3 p2 p4 na na2)(setq mod nil)))(setq n(+ n 1)))(if mod(progn(setq e1(entget na)
e1(subst(cons 10 p1)(assoc 10 e1)e1)e1(subst(cons 11 p2)(assoc 11 e1)e1))(entmod e1)))(list j ss2))(defun acet-overkill-resolve-arcs2(lst ss2 fuz no-partial no-endtoend /  index slope n x na na2 a b a2 b2 mod j e1)(setq lst(cdr lst)lst(mapcar '(lambda(x / a b)(setq a(acet-angle-format(nth 2 x))b(acet-angle-format(nth 3 x)))(if(<= b a)(setq b(+ b pi pi)))(list(nth 0 x)(nth 1 x)a b(nth 4 x)))lst)lst(vl-sort lst '(lambda(a b)(<(nth 2 a)(nth 2 b))))x(car lst)a(nth 2 x)b(nth 3 x)na(nth 4 x)j 0)(setq n 1)(repeat(-(length lst)1)(setq x(nth n lst)a2(nth 2 x)b2(nth 3 x)na2(nth 4 x))(cond((equal a2 b 0.00000001)(if(not no-endtoend)(progn (if(> b2 b)(setq b b2 mod T))(setq ss2(ssadd na2 ss2))(setq j(+ j 1)))))((< a2 b)(if(not no-partial)(progn(if(> b2 b)(setq b b2 mod T))(setq ss2(ssadd na2 ss2))(setq j(+ j 1)))))(T(if mod(progn(setq e1(entget na))(if(acet-angle-equal a b 0.00000001)(progn(setq e1(subst '(0 . "CIRCLE")(assoc 0 e1)e1)e1(vl-remove(assoc 50 e1)e1)e1(vl-remove(assoc 51 e1)e1))
(while(assoc 100 e1)(setq e1(vl-remove(assoc 100 e1)e1)))(entmake e1)(entdel na)(setq na(entlast)))(progn(setq e1(subst(cons 50 a)(assoc 50 e1)e1)e1(subst(cons 51 b)(assoc 51 e1)e1))(entmod e1)))))(setq a a2 b b2 na na2)(setq mod nil)))(setq n(+ n 1)))(if mod(progn(setq e1(entget na))(if(acet-angle-equal a b 0.00000001)(progn(setq e1(subst '(0 . "CIRCLE")(assoc 0 e1)e1)e1(vl-remove(assoc 50 e1)e1)e1(vl-remove(assoc 51 e1)e1))(while(assoc 100 e1)(setq e1(vl-remove(assoc 100 e1)e1)))(entmake e1)(entdel na)(setq na(entlast)))(progn(setq e1(subst(cons 50 a)(assoc 50 e1)e1)e1(subst(cons 51 b)(assoc 51 e1)e1))(entmod e1)))))(list j ss2))(defun acet-overkill-line-data2(e1 fuz genprops / p1 p2 dx dy dz m b m2 b2 xv th)(setq p1(cdr(assoc 10 e1))p2(cdr(assoc 11 e1))dx(-(car p2)(car p1))dy(-(cadr p2)(cadr p1))dz(-(caddr p2)(caddr p1)))(if(and(/= dx 0.0)(setq m(/ dy dx))		(<(abs m)1.0e+010))(progn(setq b(-(cadr p1)	(* m(car p1)))))(setq m nil b(car p1)))(if(and m(equal m 0.0 0.00000001))(progn
(if(and(/= dx 0.0)(setq m2(/ dz dx))		(<(abs m2)1.0e+010))(setq b2(-(caddr p1)	(* m2(car p1))))(setq m2 nil b2(car p1))))(progn(if(and(/= dy 0.0)(setq m2(/ dz dy))		(<(abs m2)1.0e+010))(setq b2(-(caddr p1)	(* m2(cadr p1))))(setq m2 nil b2(cadr p1)))))(if m(setq m(acet-calc-round m 0.00000001))	)(if m2(setq m2(acet-calc-round m2 0.00000001))	)(setq b(acet-calc-round b fuz)			 b2(acet-calc-round b2 fuz)			)(if(setq th(cdr(assoc 39 e1)))(setq xv(cdr(assoc 210 e1))xv(mapcar '(lambda(x)(acet-calc-round x 0.00000001))xv)))(if xv(list 0 m b m2 b2 xv(acet-overkill-gen-prop-get2 e1 genprops)	)(list 0 m b m2 b2(acet-overkill-gen-prop-get2 e1 genprops)	)))(defun acet-overkill-gen-prop-get2(e1 genprops / a lst)(foreach gcode genprops(if(not(setq a(assoc gcode e1)))(setq a(list gcode)))(setq lst(cons a lst)))lst)(defun acet-rtos2(val / a b units old_dimzin)(setq units(getvar"lunits"))(if(or(= units 4)(= units 5))(rtos val)(progn(setq old_dimzin(getvar"dimzin"))
(setvar"dimzin"(logand old_dimzin(~ 8)))(setq a(rtos val))(setvar"dimzin"(logior old_dimzin 8))(setq b(rtos val units 15))(setvar"dimzin"old_dimzin)(if(equal(distof a)(distof b)0.00000000000001)a b))))(defun acet-overkill-ss->primitives2(ss fuz ignore /  flt lst gcode genprops n na e1 tp a b gen c d xv  vlst tmp alst lst2 lst3 j len k)(acet-ss-clear-prev)(command"_.select"ss)(while(wcmatch(getvar"cmdnames")"*SELECT*")(command""))(setq flt '((-4 . "<OR")(0 . "LINE")(0 . "ARC")(0 . "CIRCLE")(0 . "LWPOLYLINE")(-4 . "<AND")(0 . "POLYLINE")(-4 . "<NOT")(-4 . "&")(70 . 88)(-4 . "NOT>")(-4 . "AND>")(-4 . "OR>"))ss(ssget"_p"flt))(if(not ss)(setq ss(ssadd)))(setq lst '(8 6 39 62 370 390))(foreach gcode lst(if(not(member gcode ignore))(setq genprops(cons gcode genprops))))(setq lst nil)(setq len(sslength ss)k(/ len 5)j 1)(acet-ui-progress-init"Gathering line, arc and circle data "len)(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)lst nil)(cond((and(setq e1(entget na)tp(cdr(assoc 0 e1)))
(= tp"LINE"))(setq a(cdr(assoc 10 e1))b(cdr(assoc 11 e1))lst(list a b na)gen(acet-overkill-line-data2 e1 fuz genprops)))((or(= tp"ARC")(= tp"CIRCLE"))(setq a(cdr(assoc 50 e1))b(cdr(assoc 51 e1))c(cdr(assoc 10 e1))			 d(cdr(assoc 40 e1))			 c(list(acet-calc-round(car c)fuz)(acet-calc-round(cadr c)fuz)(acet-calc-round(caddr c)fuz))d(acet-calc-round d fuz)xv(cdr(assoc 210 e1))xv(list(acet-calc-round(car xv)0.00000001)(acet-calc-round(cadr xv)0.00000001)(acet-calc-round(caddr xv)0.00000001))gen(list 1						 c 						 d						 xv						(acet-overkill-gen-prop-get2 e1 genprops)	))(if(not a)(setq a 0.0 b(+ pi pi)))(setq lst(list(cdr(assoc 10 e1)) 	(cdr(assoc 40 e1)) 	 a				 b				 na))))(if(= j k)(progn(acet-ui-progress-safe(fix(* 0.5 n)))(setq j 1))(setq j(+ j 1)))(if lst(setq vlst(cons(list gen lst)vlst)))(setq n(+ n 1)))(setq j(/ len 2))(acet-ui-progress-safe j)(setq vlst(vl-sort vlst '(lambda(a b)(>(car(car a))(car(car b)))	)))(while(and(setq a(car vlst))(=(car(car a))1))
(setq alst(cons a alst)vlst(cdr vlst)))(setq j(+ j(fix(* 0.05 len))))(acet-ui-progress-safe j)(setq vlst(vl-sort vlst			 '(lambda(a b)(setq a(car a)b(car b))(<(nth 2 a)(nth 2 b))	)))(setq j(+ j(fix(* 0.2 len))))(acet-ui-progress-safe j)(setq alst(vl-sort alst			 '(lambda(a b)(setq a(car a)b(car b))(<(nth 2 a)(nth 2 b))	)))(setq j(+ j(fix(* 0.1 len))))(acet-ui-progress-safe j)(while(setq lst(car vlst))			(setq vlst(cdr vlst)a(nth 2(car lst))	 lst2(list lst))(while(and(setq b(car vlst))(equal a(nth 2(car b))))(setq vlst(cdr vlst)lst2(cons b lst2)))(setq lst3(cons lst2 lst3)))(setq j(+ j(fix(* 0.05 len))))(acet-ui-progress-safe j)(setq vlst nil lst2 nil)(foreach lst lst3				(setq lst2(acet-list-group-by-assoc lst))(if(equal 1(length lst2))(setq vlst(cons(car lst2)vlst))(setq vlst(append lst2 vlst))))(setq lst3 nil)(while(setq lst(car alst))(setq alst(cdr alst)a(nth 2(car lst))	 lst2(list lst))(while(and(setq b(car alst))(equal a (nth 2(car b))))(setq alst(cdr alst)lst2(cons b lst2)))
(setq lst3(cons lst2 lst3)))(setq j(+ j(fix(* 0.05 len))))(acet-ui-progress-safe j)(setq alst nil lst2 nil)(foreach lst lst3(setq lst2(acet-list-group-by-assoc lst))(if(equal 1(length lst2))(setq alst(cons(car lst2)alst))(setq alst(append lst2 alst))))(acet-ui-progress-done)(append vlst alst))
