(defun c:torient(/ ss flt j mode)(acet-error-init(list(list"cmdecho"0"highlight"(getvar"highlight")"limcheck"0"pickstyle"0)T))(setq flt '((-4 . "<OR")(0 . "TEXT")(0 . "ATTDEF")(0 . "MTEXT")(-4 . "<AND")(0 . "INSERT")(66 . 1)(-4 . "AND>")(-4 . "OR>")))(princ"\n选择文本,多行文本,特性或块插入 w/特性...")(if(and(setq ss(ssget flt))(setq ss(car(acet-ss-filter(list ss '(("LAYERUNLOCKED")("CURRENTUCS"))T)))))(progn(setq ss(bns_annotation_ss ss))(setq mode(getangle"\n新的绝对变为 <最大可读>: "))(setvar"highlight"0)(setq j(bns_trot ss mode))(if ss(command"_.select"ss""))(princ(strcat"\n"(itoa j)" 个对象已更新.")))(princ"\n没有选择有效的对象。"))(acet-error-restore))(defun c:tcircle(/ ss flt j rad ent offset slot)(acet-error-init(list(list"cmdecho"0"highlight"(getvar"highlight")"limcheck"0)T))(setq flt '((-4 . "<OR")(0 . "TEXT")(0 . "ATTDEF")(0 . "MTEXT")(-4 . "OR>")))(princ"\n选择文字,多行文字或对象属性...")(if(and(setq ss(ssget flt))(setq ss(car(acet-ss-filter(list ss '(("LAYERUNLOCKED")
("CURRENTUCS"))T)))))(progn(if(not #bns_tcircle_offset)(setq #bns_tcircle_offset 0.35))(initget 6)(setq offset(getreal(strcat"\n输入偏移距离 <"(rtos #bns_tcircle_offset 2(getvar"luprec"))">: ")))(if(or(not offset)(equal offset""))(setq offset #bns_tcircle_offset)(setq #bns_tcircle_offset offset))(if(not #bns_tcircle_ent)(setq #bns_tcircle_ent"Circles"))(initget"Circles Slots Rectangles")(setq ent(getkword(acet-str-format"\n弧形文本宽度 [圆(C)/细长(S)/矩形(R)] <%1>: "#bns_tcircle_ent)))(if(or(not ent)(equal ent""))(setq ent #bns_tcircle_ent)(setq #bns_tcircle_ent ent))(if(not #bns_tcircle_rad)(setq #bns_tcircle_rad"Variable"))(initget"Constant Variable")(setq rad(getkword(acet-str-format "\n创建常数或变量的%1 [常数(C)/变量(V)] <%2>: "(strcase ent T)#bns_tcircle_rad)))(if(or(not rad)(equal rad""))(setq rad #bns_tcircle_rad)(setq #bns_tcircle_rad rad))(if(and(equal rad"Constant")(or(equal ent"Slots")(equal ent"Rectangles")))(progn(if(not #bns_tcircle_slot)(setq #bns_tcircle_slot"Both"))
(initget"Width Height Both")(setq slot(getkword(acet-str-format"\n保持常数 %1 [宽度(W)/高度(H)/两者(B)] <%2>: "(strcase(substr ent 1(-(strlen ent)1))T)#bns_tcircle_slot)))(if(or(not slot)(equal slot""))(setq slot #bns_tcircle_slot)(setq #bns_tcircle_slot slot))))(setq j(bns_tcircle ss rad ent slot offset))(if ss(command"_.select"ss""))(princ(strcat"\n"(itoa j)" "ent" 个已创建。")))(princ"\n无选择可用对象."))(acet-error-restore))(defun c:tcount(/ ss_sort ss start inc startinc flag flt n)(acet-error-init(list(list"cmdecho"0"highlight"(getvar"highlight")"limcheck"0)T))(setq flt '((-4 . "<OR")(0 . "TEXT")(0 . "MTEXT")(0 . "ATTDEF")(-4 . "OR>")))(if(and(setq ss(ssget flt))(setq ss(car(acet-ss-filter(list ss '(("LAYERUNLOCKED")("CURRENTUCS"))T)))))(progn(if(not #bns_tcount_sort)(setq #bns_tcount_sort"Select-order"))(initget"X Y Select-order")(setq ss_sort(getkword(acet-str-format"\n选择对象种类按照 [X/Y/选择顺序(S)] <%1>: "#bns_tcount_sort)))(if(or(not ss_sort)(equal ss_sort""))
(setq ss_sort #bns_tcount_sort)(setq #bns_tcount_sort ss_sort))(if(not #bns_tcount_start)(setq #bns_tcount_start 1))(if(not #bns_tcount_inc)(setq #bns_tcount_inc 1))(while(not flag)(setq flag T)(setq startinc(strcat(itoa(fix #bns_tcount_start))","(itoa(fix #bns_tcount_inc)))startinc(getstring(acet-str-format"\n指定开始编号和增量 (开始,增量) <%1>: "startinc)))(if(equal startinc"")(setq startinc(strcat(itoa(fix #bns_tcount_start))","(itoa(fix #bns_tcount_inc)))))(setq startinc(acet-str-to-list","startinc))(if(or(not(car startinc))(not(numberp(read(car startinc))))(and(cadr startinc)(not(numberp(read(cadr startinc))))))(progn(princ"\n输入错误.")(setq flag nil)))(setq start(atoi(car startinc)))(if(cadr startinc)(setq inc(atoi(cadr startinc)))(setq inc 1))(if start(setq #bns_tcount_start start))(if(or(not inc)(equal inc 0))(setq inc #bns_tcount_inc))(if inc(setq #bns_tcount_inc inc)))(bns_get_tcountmode_cmd)(setq n(bns_tcount ss ss_sort start inc #bns_tcount_mode #bns_tcount_replace))
(princ(acet-str-format"\n%1 对象更新."(itoa n)))(if ss(command"_.select"ss""))))(acet-error-restore))(defun c:tjust(/ flag ss flt)(acet-error-init(list(list"cmdecho"0)T))(setq flt '((-4 . "<OR")(0 . "TEXT")(0 . "ATTDEF")(0 . "MTEXT")(-4 . "<AND")(0 . "INSERT")(66 . 1)(-4 . "AND>")(-4 . "OR>")))(if(and(setq ss(ssget flt))(setq ss(car(acet-ss-filter(list ss '(("LAYERUNLOCKED")("CURRENTUCS"))T)))))(progn(setq ss(acet-ss-annotation-filter ss))(if(not #bns_tjust)(setq #bns_tjust"Start"))(princ"\n输入新的对齐方式...")(initget"Start Center Middle Right TL TC TR ML MC MR BL BC BR")(setq flag(getkword(acet-str-format"\n[起点(S)/中心(C)/中间(M)/右(R)/左上(TL)/中上(TC)/右上(TR)/左中(ML)/正中(MC)/右中(MR)/左下(BL)/中下(BC)/右下(BR)] <%1>: "#bns_tjust)))(if(or(not flag)(equal flag""))(setq flag #bns_tjust))(acet-tjust ss flag)(if ss(command"_.select"ss""))(princ(strcat"\n"(itoa(sslength ss))" 个对象已更新."))(setq #bns_tjust flag)))(acet-error-restore))(defun bns_get_tcountmode_cmd(/ a r)
(if(not #bns_tcount_mode)(setq #bns_tcount_mode"Prefix"))(if(not #bns_tcount_replace)(setq #bns_tcount_replace""))(initget"Overwrite Prefix Suffix Find&replace")(setq a(getkword(acet-str-format"\n布置文本中的数字[覆盖(O)/前缀(P)/后缀(S)/查找替换(F)..] < %1>: "#bns_tcount_mode)))(if(or(not a)(equal a""))(setq a #bns_tcount_mode))(setq #bns_tcount_mode a)(if(equal a"Find&replace")(progn(setq r"")(while(equal r"")(setq r(getstring T(strcat"\n输入搜索字符串 <"#bns_tcount_replace">: ")))(if(not(equal r""))(setq #bns_tcount_replace r)(setq r #bns_tcount_replace))(if(equal r"")(princ"*无效* 不允许空的字符串。")))))#bns_tcount_mode)(defun bns_tcount(ss ss_sort start inc mode str / a na e1 e2 n lst b j)(if(not(equal"Select-order"ss_sort))(progn(cond((equal"X"ss_sort)(setq ss(bns_esort ss '((e1)(car(cdr(assoc 10 e1)))))))((equal"Y"ss_sort)(setq ss(bns_esort ss '((e1)(* -1.0(cadr(cdr(assoc 10 e1))))))))((equal"Z"ss_sort)(setq ss(bns_esort ss '((e1)(caddr(cdr(assoc 10 e1))))))))))(setq j 0)
(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na)e2 e1)(cond((equal"TEXT"(cdr(assoc 0 e1)))(setq a(itoa start))(setq a(place_tcount(cdr(assoc 1 e1))a mode str))(entmod(subst(cons 1 a)(assoc 1 e1)e1)))((equal"MTEXT"(cdr(assoc 0 e1)))(setq a"")(foreach x e1 (if(=(car x)3)(setq a(strcat a(cdr x)))))(setq a(strcat a(cdr(assoc 1 e1)))lst(acet-str-to-list"\\P"a)b"")(foreach x lst(setq a(itoa start))(setq a(place_tcount x a mode str)b(strcat b"\\P"a))(setq start(+ start inc)))(setq start(- start inc))(setq b(substr b 3)lst nil)(foreach x e1(if(and(/=(car x)3)(/=(car x)1))(setq lst(append lst(list x)))))(setq e1 lst)(while(>(strlen b)250)(setq e1(append e1 (list(cons 3(substr b 1 250))))b(substr b 251)))(setq e1(append e1(list(cons 1 b))))(entmod e1))((equal"ATTDEF"(cdr(assoc 0 e1)))(setq a(itoa start))(setq a(place_tcount(cdr(assoc 2 e1))a mode str))(setq a(acet-str-replace" """a))(entmod(subst(cons 2 a)(assoc 2 e1)e1))))(if(not(equal e2(entget(cdr(assoc -1 e2)))))
(setq j(+ j 1)))(setq n(+ n 1))(setq start(+ start inc)))j)(defun place_tcount(org num mode str /)(cond((or(not mode)(equal mode"Overwrite"))(setq str num))((equal mode"Prefix")(setq str(strcat num" "org)))((equal mode"Suffix")(setq str(strcat org" "num)))((equal mode"Find&replace")(setq str(acet-str-replace str num org))))str)(defun bns_tcircle(ss rad ent slot offset / a b d na e1 n j lst ll lr ul ur addw addh p0 p1 p2 p3 w h slot down left right up)(setq j 0)(if(equal"Variable"rad)(progn(princ(strcat"\n创建 "ent"..."))(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na)a(acet-geom-textbox e1 offset)b(acet-geom-midpoint(car a)(caddr a)))(if(equal"Circles"ent)(entmake(list '(0 . "CIRCLE")(cons 10(trans b 1(cdr(assoc 210 e1))))(cons 40(distance(car a)b))(assoc 210 e1)))(entmake(list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")'(100 . "AcDbPolyline")'(90 . 4)(cons 38(last(cdr(assoc 10 e1))))'(70 . 1)(cons 10(trans(nth 0 a)1(cdr(assoc 210 e1))))(if(equal ent"Rectangles")
'(42 . 0.0)'(42 . -1.0))(cons 10(trans(nth 3 a)1(cdr(assoc 210 e1))))'(42 . 0.0)(cons 10(trans(nth 2 a)1(cdr(assoc 210 e1))))(if(equal ent"Rectangles")'(42 . 0.0)'(42 . -1.0))(cons 10(trans(nth 1 a)1(cdr(assoc 210 e1))))'(42 . 0.0)(assoc 210 e1))))(setq j(+ j 1))(setq n(+ n 1)))(princ"Done."))(progn(if(equal"Circles"ent)(progn(princ"\n输入最佳半径...")(setq n 0 d -99999.0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na)a(acet-geom-textbox e1 offset)b(acet-geom-midpoint(car a)(caddr a)))(setq lst(append lst(list(list(trans b 1(cdr(assoc 210 e1)))(assoc 210 e1)))))(if(>(distance(car a)b)d)(setq d(distance(car a)b)))(setq n(+ n 1)))(princ"完成。")(princ(strcat"\n创建 "ent"..."))(setq n 0)(repeat(length lst)(setq a(nth n lst))(entmake(list '(0 . "CIRCLE")(cons 10(car a))(cons 40 d)(cadr a)))(setq j(+ j 1))(setq n(+ n 1))))(progn(princ"\n输入最佳大小...")(setq n 0 w -99999.0 h -99999.0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na)a(acet-geom-textbox e1 offset))
(if(>(distance(car a)(cadr a))w)(setq w(distance(car a)(cadr a))))(if(>(distance(nth 0 a)(nth 3 a))h)(setq h(distance(nth 0 a)(nth 3 a))))(setq n(+ n 1)))(princ"完成。")(princ(strcat"\n创建 "ent"..."))(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na)a(acet-geom-textbox e1 offset))(setq ll(nth 0 a)lr(nth 1 a)ur(nth 2 a)ul(nth 3 a))(setq left(angle lr ll)right(angle ll lr)up(angle ll ul)down(angle ul ll))(if(or(equal"Width"slot)(equal"Both"slot))(setq addw(/(- w(distance ll lr))2))(setq addw 0))(if(or(equal"Height"slot)(equal"Both"slot))(setq addh(/(- h(distance ll ul))2))(setq addh 0))(setq p0(polar(polar ll left addw)down addh)p1(polar(polar lr right addw)down addh)p2(polar(polar ur right addw)up addh)p3(polar(polar ul left addw)up addh))(entmake(list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")'(100 . "AcDbPolyline")'(90 . 4)(cons 38(last(cdr(assoc 10 e1))))'(70 . 1)(cons 10(trans p0 1(cdr(assoc 210 e1))))(if(equal ent"Rectangles")'(42 . 0.0)'(42 . -1.0))
(cons 10(trans p3 1(cdr(assoc 210 e1))))'(42 . 0.0)(cons 10(trans p2 1(cdr(assoc 210 e1))))(if(equal ent"Rectangles")'(42 . 0.0)'(42 . -1.0))(cons 10(trans p1 1(cdr(assoc 210 e1))))'(42 . 0.0)(assoc 210 e1)))(setq j(+ j 1))(setq n(+ n 1)))))(princ"完成。")))j)(defun bns_trot(ss mode / na e1 n a b j)(setq j 0)(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na))(if(="MTEXT"(cdr(assoc 0 e1)))(setq a(cdr(assoc 50 e1)))(setq a(acet-geom-angle-trans(cdr(assoc 50 e1))na 1)))(setq a(- a(getvar"angbase")))(if(not mode)(progn(setq a(*(/ 180.0 pi)a))(if(< a 0)(setq a(+ a 360)))(if(and(> a 100.0)(< a 280.0))(progn(bns_rotate_text e1 pi)(setq j(+ j 1)))))(progn(setq a(- mode a))(bns_rotate_text e1 a)(setq j(+ j 1))))(setq n(+ n 1)))j)(defun bns_rotate_text(e1 ang / p1 p2 a)(setq p1(acet-geom-textbox e1 0.2)p1(acet-geom-midpoint(car p1)(caddr p1))a(cdr(assoc 50 e1))a(+ ang a)e1(subst(cons 50 a)(assoc 50 e1)e1))(entmod e1)(entupd(cdr(assoc -1 e1)))(setq e1(entget(cdr(assoc -1 e1))))
(setq p2(acet-geom-textbox e1 0.2)p2(acet-geom-midpoint(car p2)(caddr p2))a(acet-geom-delta-vector p2 p1)a(trans a 1 na T)p1(cdr(assoc 10 e1))p1(acet-geom-vector-add p1 a)p2(cdr(assoc 11 e1))p2(acet-geom-vector-add p2 a)e1(subst(cons 10 p1)(assoc 10 e1)e1)e1(subst(cons 11 p2)(assoc 11 e1)e1))(entmod e1)(entupd(cdr(assoc -1 e1))))(defun bns_esort(ss func / a lst ss2 na e1 n)(setq ss2(ssadd))(setq n 0)(repeat(sslength ss)(setq na(ssname ss n)e1(entget na))(setq lst(cons(list(eval '(func e1))e1)lst))(setq n(+ n 1)))(setq lst(acet-list-isort lst 0))(setq n 0)(repeat(length lst)(setq a(nth n lst)a(cadr a)a(cdr(assoc -1 a))ss2(ssadd a ss2))(setq n(+ n 1)))ss2)(princ)
