(defun acet-ui-table-name-get(alst / a)(acet-arxload-or-bust"acetutil.arx")(acet-arxload-or-bust"acapp.arx")(if(or(= 0(getvar"cmddia"))(= 4(logand 4(getvar"cmdactive"))))(setq a(acet-ui-table-name-get-cmd alst))(setq a(acet-ui-table-name-get-dlg alst)))a)(defun acet-ui-table-name-get-dlg(alst / title def tblname flags flt helpfile helptopic selected-names list-pick check-name check-names iv n lst a b names msg lst2 ans flag helpstr)(defun selected-names(lst / nlst n names)(setq nlst(get_tile"name_list")nlst(acet-str-to-list" "nlst)nlst(mapcar 'atoi nlst))(foreach n nlst(setq names(cons(nth n lst)names)))(setq names(reverse names)))(defun list-pick(val reason lst flags / names)(set_tile"error""")(setq names(selected-names lst))(if(/= 32(logand 32 flags))(progn						(set_tile"name"(car names))(if(equal reason 4)		(done_dialog 1)		)))names)(defun check-names(tblname flags flt lst lst2 / a names)(set_tile"error""")(if(/= 32(logand 32 flags))(progn
(if(setq a(check-name tblname flags flt lst))(setq names(list a))))(setq names(selected-names lst2)))(if names(done_dialog 1))names)(defun check-name(tblname flags flt lst / name a b ans)(setq name(get_tile"name")name(acet-str-lr-trim" "name)name(acet-str-lr-trim"\""name)name(acet-str-lr-trim" "name))(setq a(acet-ui-table-name-get-is-valid name tblname flags flt lst)b(cadr a)a(car a)tblname(strcase(acet-ui-table-name-format tblname)T))(cond ((not a)(set_tile"error"b)(setq name nil))((and(not(assoc(xstrcase name)lst))(setq ans(acet-ui-message (acet-str-format" %1 '%2'不存在\n您想创建它吗？"tblname name)(acet-str-format"创建%1吗？"tblname)acet:yesnocancel))(/= acet:idyes ans))(setq name nil)))name)(setq lst '(title def tblname flags flt helpfile helptopic))(setq n 0)(repeat(min(length lst)(length alst))(set(nth n lst)(nth n alst))(setq n(+ n 1)))(cond((and(not helpfile)(not helptopic))(setq helpstr"(acet-help)"))((and helpfile helptopic)
(setq helpstr(acet-str-format"(acet-help \"%1\")"helptopic)))(helptopic(setq helpstr(acet-str-format"(acet-help \"%1\")"helptopic))))(setq flags(acet-ui-table-name-check-flags tblname flags flt)flt(cadr flags)flags(car flags))(setq lst(acet-ui-table-name-get-item-list tblname flags flt)lst2(mapcar '(lambda(x)(cdr(assoc 2(cadr x))))lst))(if lst2(setq lst2(acad_strlsort lst2))(princ"\n没有发现有效的项。"))(if(or(= 32(logand 32 flags))(not def)(not(car(acet-ui-table-name-get-is-valid def tblname flags flt lst))))(setq def(car lst2)))(while(or(not flag)(and(= flag 2)(not names)))(if(>(setq iv(load_dialog"tblname"))0)(progn(if(or(and(/= 32(logand 32 flags))	(new_dialog"tblname"iv))(and(= 32(logand 32 flags))	(new_dialog"tblname_m"iv)))(progn(if helptopic(set_tile"dlgTitle"(xstrcase helptopic)))(set_tile"msg"title)(acet-dcl-list-make"name_list"lst2)(if def(set_tile"name"def)(set_tile"name"""))(if def (set_tile"name_list"(itoa(vl-position(cdr(assoc 2(cadr(assoc(xstrcase def)lst))))lst2))))
(if(= 8(logand 8 flags))(mode_tile"pickit"1))(if(/= 32(logand 32 flags))(mode_tile"name"2))(action_tile"name_list""(setq names (list-pick $value $reason lst2 flags))")(action_tile"name"(strcat"(if (equal $reason 1)""(setq names (check-names tblname flags flt lst lst2))"")"))(action_tile"pickit""(done_dialog 2)")(action_tile"accept""(setq names (check-names tblname flags flt lst lst2))")(action_tile"cancel""(done_dialog 0)")(action_tile"help"helpstr)(setq flag(start_dialog)))(progn(alert"不能显示对话框")(setq flag 0)))(unload_dialog iv))(progn(alert"不能加载对话框")(setq flag 0)))(if(= flag 2)(setq names(acet-ui-table-name-get-pickit alst))))(if(= flag 0)(setq names nil))(if(/= 32(logand 32 flags))(setq names(car names)))names)(defun acet-ui-table-name-get-cmd(alst / title def tblname flags flt  n lst a names name msg ans opt tblname2 spc)(setq lst '(title def tblname flags flt))(setq n 0)(repeat(min(length lst)(length alst))(set(nth n lst)(nth n alst))(setq n(+ n 1)))
(setq flags(acet-ui-table-name-check-flags tblname flags flt)flt(cadr flags)flags(car flags))(setq lst(acet-ui-table-name-get-item-list tblname flags flt))(if(or(= 32(logand 32 flags))(and def(not(car(acet-ui-table-name-get-is-valid def tblname flags flt lst)))))(setq def nil))(if(= 8(logand 8 flags))(setq opt" or [?]")			(setq opt" or [?/= (select object)]"))(if def(setq msg(strcat"\n"title opt" <"def">: "))(setq msg(strcat"\n"title opt": ")))(setq tblname2(acet-ui-table-name-format tblname)tblname2(strcase tblname2 T))(while(not names)(if(= 32(logand 32 flags))(progn					(if(=(getvar"extnames")1)(setq spc T)(setq spc nil))(setq names(acet-ui-m-get-names (list spc							 msg 							(mapcar 'car lst)					(acet-str-format"No matching %1(s) found."tblname2)	)))(if(not names)(setq names(list""))))(progn					(if(=(getvar"extnames")1)(setq name(acet-ui-get-long-name msg))(setq name(acet-str-lr-trim"\""(getstring msg))))(setq names(list name))))(foreach name names
(if(and(/= 32(logand 32 flags))(= name"")def)(setq names(subst def name names)name def))(cond((or(not name)(equal name""))nil)((or(= name"=")(= name"`"))(if(/= 8(logand 8 flags))(setq name(acet-ui-table-name-get-pickit alst))(progn(princ"\nObject selection not allowed.")(setq name nil names nil)))(if name(setq names(append names name)))(setq names(vl-remove"="names)))((= name"~")(setq name(acet-ui-table-name-get-dlg alst))(if name(setq names(append names(list name))))(setq names(vl-remove"~"names)))((equal name"?")(setq name nil)(acet-ui-table-name-get-cmd-list(acet-str-format"\n输入%1名称以列出 <*>: "tblname2)lst)(setq names(vl-remove"?"names)))((and(setq a(acet-ui-table-name-get-is-valid name tblname flags flt lst))(car a))(if(and(not(assoc(xstrcase name)lst))(progn(initget"Yes No _Yes _No")(setq ans(getkword (acet-str-format "\n%1 '%2'不存在。您想创建它吗？ <是>:"tblname2 name)))(or(= ans"No")(= ans"_No"))))(setq name nil names nil)))((cadr a)(princ(strcat"\n"(cadr a)))
(setq name nil names nil)))))(setq names(acet-list-remove-duplicates names nil))(if(equal names(list""))(setq names nil))(if(/= 32(logand 32 flags))(progn(setq names(car names))(if(not names)(setq names def))))names)(defun acet-ui-table-name-get-pickit(alst / tlst  title def tblname flags flt lst ss n na e1 name lst2 x flt2 gcode flag  tblname2 namelst)(setq tlst '(title def tblname flags flt lst))(setq n 0)(repeat(min(length tlst)(length alst))(set(nth n tlst)(nth n alst))(setq n(+ n 1)))(setq flags(acet-ui-table-name-check-flags tblname flags flt)flt(cadr flags)flags(car flags))(if(not lst)(setq lst(acet-ui-table-name-get-item-list tblname flags flt)))(cond((acet-str-equal"block"tblname)(setq gcode 2 flt2 '((0 . "INSERT"))))((acet-str-equal"dimstyle"tblname)(setq gcode 3 flt2 '((-4 . "<OR")(0 . "DIM*")(0 . "LEADER")(-4 . "OR>"))))((acet-str-equal"style"tblname)(setq gcode 7 flt2 '((-4 . "<OR")(0 . "*TEXT")(0 . "ATTDEF")(-4 . "OR>"))))((acet-str-equal"layer"tblname)(setq gcode 8 
flt2 '((8 . "*"))))((acet-str-equal"ltype"tblname)(setq gcode 6 flt2 '((6 . "*"))))((acet-str-equal tblname"ACAD_GROUP")(setq gcode 330 flt2 '((0 . "*"))))((acet-str-equal tblname"ACAD_PLOTSTYLENAME")(setq gcode 390 flt2 '((0 . "*"))))((acet-str-equal tblname"ACAD_MLINESTYLE")(setq gcode 2 flt2 '((0 . "MLINE"))))((acet-str-equal tblname"ACAD_PLOTSETTINGS")(setq gcode 330 flt2 '((0 . "*"))flag T)(princ"\n不能选择对象以得到页面设置信息。"))((acet-str-equal tblname"ACAD_LAYOUT")(setq gcode 410 flt2 '((0 . "*"))))(T(setq flag T)(print tblname)(princ"\n未知的表类型在acet-ui-table-name-get。")))(setq tblname2(strcase(acet-ui-table-name-format tblname)T))(if(= 32(logand 32 flags))(princ(acet-str-format"\n用希望的%1名称选择对象..."tblname2))(princ(acet-str-format"\n用希望的%1名称选择一个对象..."tblname2)))(while(and(not flag)(setq ss(acet-ui-entsel (list"\n选择对象: "	 nil			 nil			 T				 flt2			 T				))))(setq n 0)(repeat(sslength ss)(setq na(ssname ss n))(if(and na(setq e1(entget na)))(progn
(setq name(acet-ui-table-name-object-data tblname e1 gcode))(cond((not name)(princ(acet-str-format"\n指定不包含%1数据的对象。"tblname2)))((and(/= 16(logand 16 flags))(or(acet-str-equal"BYLAYER"name)(acet-str-equal"BYLAYER"name)))(princ(acet-str-format"\n%1不允许。"(xstrcase name)))(setq name nil))(T(setq flag(acet-ui-table-name-get-is-valid name tblname flags flt lst))(if(not(car flag))(progn(princ name)(princ"\n")(princ(cadr flag))(setq flag nil name nil))))))(setq name nil))(if(= 32(logand 32 flags))(setq flag nil))(if(and name(not(member name namelst)))(setq namelst(cons name namelst)))(setq n(+ n 1)))(if namelst(progn(if(= 32(logand 32 flags))(progn(princ(acet-str-format"\n选择%1(s): "tblname2))(foreach x(reverse namelst)(princ x)(if(not(equal x(car namelst)))(princ", ")))(princ(chr 8))(princ(chr 8)))(princ(acet-str-format"\n选择%1是: %2。"tblname2(car namelst)))))))(setq namelst(reverse namelst))namelst)(defun acet-ui-table-name-get-cmd-list(msg lst / wld flag x)
(setq wld(getstring T msg))(if(equal(acet-str-lr-trim" "wld)"")(setq wld"*"))(setq lst(mapcar 'car lst)lst(acad_strlsort lst))(foreach x lst(if(wcmatch x wld)(progn(princ(strcat"\n"x))(setq flag T))))(if(not flag)(princ"\n没有找到匹配的名称。")))(defun acet-ui-table-name-get-is-valid(name tblname flags flt lst / x msg na e1 ok dict extnames)(setq x name  name(xstrcase name)tblname(strcase tblname T)na(acet-ui-table-name-get-ename tblname name))(if(acet-is-symbol-table tblname)(setq extnames(getvar"extnames"))(progn(setq extnames 1 tblname(acet-ui-table-name-format tblname)tblname(strcase tblname T))))(cond((and(not(snvalid name))			)(cond((and(= 1 extnames)(>(strlen name)255))(setq msg"%1名称无效。\n最大字符长度为255。"))((and(= 0(getvar"extnames"))(>(strlen name)255))(setq msg"%1名称无效。\n最大字符长度为31。"))(T (acet-sysvar-set '("extnames"1))(if(snvalid name)(setq msg" %1名称无效。 (\"EXTNAMES\"=0)")(setq msg" %1名称里有无效的字符。\n 下面的字符是无效的:\n <>\\/\":?*|,=`"))
(acet-sysvar-restore))))((and(not na)			(or(/= 1(logand 1 flags))(= 4(logand 4 flags))))(setq msg"%1 '%2'没有发现。"))((and (= 2(logand 2 flags)) 	 na(or(= 16(logand 16(cdr(assoc 70(entget na)))))	(and(acet-str-equal"block"tblname)(= 4(logand 4(cdr(assoc 70(entget na))))))))(setq msg"不允许外部的依靠%1。"))((and na 				(= 4(logand 4 flags))(not(assoc name lst)))(setq e1(entget na))(while(bns_filter_match e1(car(car flt)))(setq flt(cdr flt)))(setq msg(cadr(car flt))))((or na 			(snvalid name))(setq ok T)))(if msg(setq msg(acet-str-format msg(strcase tblname T)x)))(list ok msg))(defun acet-ui-table-name-get-item-list(tblname flags flt / tmp lst lst2 x name symtbl)(foreach x flt(setq lst(append(car x)lst)))(setq flt lst tmp flt)(if(= 2(logand 2 flags))(progn(if(acet-str-equal tblname"block")(setq flt(append flt '((-4 . "<AND")(-4 . "<NOT")(-4 . "&")(70 . 16)(-4 . "NOT>")	(-4 . "<NOT")(-4 . "&")(70 . 4)(-4 . "NOT>")	(-4 . "AND>"))))(setq flt(append flt 
'((-4 . "<NOT")(-4 . "&")(70 . 16)(-4 . "NOT>")))))))(cond((not flt)(setq flt '((0 . "*"))))(tmp(setq flt(append '((-4 . "<AND"))flt '((-4 . "AND>"))))))(if(setq symtbl(acet-is-symbol-table tblname))(setq lst(bns_tbl_match tblname flt))(setq lst(acet-dict-filter-match tblname flt)))(if(= 16(logand 16 flags))(setq lst2(list '("BYLAYER"((2 . "ByLayer")))'("BYBLOCK"((2 . "ByBlock"))))))(foreach x lst(setq name(cdr(assoc 2 x)))(if(or(not symtbl)(snvalid name))(setq lst2(cons(list(xstrcase name)x)lst2))))lst2)(defun acet-ui-table-name-format(tblname /)(cond((acet-str-equal tblname"ACAD_GROUP")(setq tblname"Group"))((acet-str-equal tblname"ACAD_PLOTSTYLENAME")(setq tblname"PlotStyle"))((acet-str-equal tblname"ACAD_MLINESTYLE")(setq tblname"MlineStyle"))((acet-str-equal tblname"ACAD_PLOTSETTINGS")(setq tblname"PageSetup"))((acet-str-equal tblname"ACAD_LAYOUT")(setq tblname"Layout"))((acet-str-equal tblname"LTYPE")(setq tblname"LineType")))tblname)
(defun acet-ui-table-name-get-ename(tblname name / na)(if(acet-is-symbol-table tblname)(setq na(tblobjname tblname name))(setq na(acet-dict-ename tblname name)))na)(defun acet-is-symbol-table(str / lst)(setq lst '("APPID""BLOCK""LAYER""LTYPE""STYLE""DIMSTYLE""VIEW""UCS"))(if(member(xstrcase str)lst)T nil))(defun acet-dict-filter-match(tblname flt / n lst na e1 lst2)(acet-autoload '("acetflt.lsp""(bns_filter_match tblname flt)"))(setq lst(acet-dict-name-list tblname))(setq n 0)(repeat(length lst)(setq na(acet-dict-ename tblname(nth n lst))e1(entget na))(if(bns_filter_match e1 flt)(setq e1(cons(cons 2(nth n lst))e1)lst2(append lst2(list e1))))(setq n(+ n 1)))lst2)(defun acet-ui-table-name-object-data(tblname e1 gcode / lst lst2 na name)(cond((acet-str-equal tblname"ACAD_GROUP")(setq lst(acet-dict-name-list tblname)lst2(mapcar '(lambda(x)(acet-dict-ename tblname x))lst)e1(acet-list-m-assoc 330 e1)e1(mapcar 'cdr e1))(while(setq na(car e1))(setq e1(cdr e1))(if(member na lst2)
(setq name(nth(vl-position na lst2)lst)e1 nil))))((acet-str-equal tblname"ACAD_PLOTSTYLENAME")(if(setq na(cdr(assoc 390 e1)))(progn(setq lst(acet-dict-name-list tblname)lst2(mapcar 'acet-dict-ename lst))(setq name(nth(vl-position na lst2)lst)))(setq name"BYLAYER")))(T(if(setq gcode(cdr(assoc gcode e1)))(setq name gcode)(setq name"BYLAYER"))))name)(defun acet-ui-table-name-check-flags(tblname flags flt /)(if(/= 4(logand 4 flags))(setq flt nil))(if(and(acet-str-equal tblname"ACAD_PLOTSETTINGS")(/= 8(logand 8 flags)))(setq flags(+ flags 8)))(if(and(= 16(logand 16 flags))(not(or(acet-str-equal tblname"ACAD_PLOTSTYLENAME")(acet-str-equal tblname"ltype"))))(setq flags(- flags 16)))(list flags flt))(princ)
