AutoCAD内常用术语的自动标注方法
摘要<FONT face="Times New Roman"> </FONT>本文提出了一种用对话框实现<FONT face="Times New Roman">AutoCAD</FONT>内常用术语自动标注的方法。用这种方法,可方便地将各种常用术语标注在图中,为<FONT face="Times New Roman">CAD</FONT>应用提供了方便。<FONT face="Times New Roman"> </FONT><P><FONT face="Arial Unicode MS">一、引言 </FONT></P>
<P><FONT face="Arial Unicode MS"> 汉字的标注在CAD设计制图中是一个重要的部分,也是一个较为繁琐、困难的部分。目前,在AutoCAD内汉字的输入大多采用拼音方式,对拼音不熟悉的人来说汉字的输入就很困难。如果能将设计中常用的文字术语直观地显示出来供设计人员调用,将会极大地提高工作效率。本文就此进行研究,提出了一种用对话框(下图)将常用术语显示并供调用的方法,同时给出了源程序,供大家参考。该程序已应用于我院的实际生产中。</FONT></P>
<P><IMG src="http://www.cadx.cn/data/uploadfile/200608/20060827235741769.jpg"></P>
<P align=left><FONT face="Arial Unicode MS">二、原理及方法 </FONT></P>
<P><FONT face="Arial Unicode MS"> AutoCAD对话框结构包含有多种构件,如edit_box(编辑框)、list_box(列表框)、radio_button(多选一按钮)等,利用这些工具,可以开发出界面友好的实用程序。</FONT></P>
<P><FONT face="Arial Unicode MS"> 左图就是用这种方法实现的。将常用词组分类,分别存于不同的文件中。根据多选一按钮中所驱动的分组号分别打开不同的文件,将文件内容读入并显示于列表框内,供设计人员使用。同时,设有一个编辑框,可将所点取的词组显示于编辑框中,便于用户对词组进行适当的修改,如删除或增加字符等。这种方法有一个优点,用户可十分方便地根据自己需要修改或添加词组内容。对话框文件及驱动程序分别见#CAL.DCL及#CAL.LSP。</FONT></P>
<P><FONT face="Arial Unicode MS">三、程序使用方法 </FONT></P>
<P><FONT face="Arial Unicode MS">先用WPS、EDIT等编辑程序分类建立词组库(注意,需要存成纯文本格式),每个词组占一行。程序要求将"常用术语"、"图纸名称"、"房间名称"等各分类所对应的词组库文件名分别为$TXT1.DAT、$TXT2.DAT、$TXT3.DAT厖。除第一个文件不能少外,其它文件可空缺,但当点取该分类项时,系统会提示有关文件不存在的信息。</FONT></P>
<P><FONT face="Arial Unicode MS">然后将所建立的词组库文件及所提供的程序#TXT.LSP和对话框文件#TXT.DCL拷贝到AutoCAD所能找到的目录(环境变量ACAD所设置的任一目录如ACAD\SUPPORT或当前目录)中,在Command:命令下键入(LOAD "#TXT")进行程序的加载,即可象其它AutoCAD内部命令一样使用#TXT了。也可在所使用的菜单文件(如ACAD.MNU)中的下拉式菜单或屏幕菜单部分加上下面一行:[常用词组]^C^C^P(if (null c:#txt) (load"#txt")) #txt以后可直接从菜单中驱动该程序。</FONT></P>
<P><FONT face="Arial Unicode MS">在COMMAND:状态下,键入#TXT后,系统弹出一个对话框,根据需要点取所需的词组类别,再从列表框内选择所需词组。所点取的词组会在编辑框[所选词组]中显示。用户可以在此对词组进行必要的修改,点取[OK]后,根据提示输入字高及起点即可把词组写到图中。</FONT></P>
<P><FONT face="Arial Unicode MS">需要说明的是,本程序中是将文字以"HZ"字型写到图中,要求字体为TXT.SHX及HZTXT.SHX。若您的软件中无这两种字体,可将其它字体改名为该两种字体(要求一个为英文字体,一个为中文字体),或将程序修改为您所具有的字体。但需要注意,也许您的字体在用于设置字型时会多一个选项,询问是否垂直书写文字,此时,可将字型设置一句改为:(command "STYLE" "HZ" "txt,hztxt" 0 0.7 0 "n" "n" "n")即可。</FONT></P>
<P><FONT face="Arial Unicode MS">本程序在AutoCAD R12.0 For DOS及For WINDOWS版上均调试通过。 </FONT></P>
<P><FONT face="Arial Unicode MS">(defun c:#txt ( / oldcmd olderr ok txt_tb txt dcl_id sty fp nn ht pt txterr diag init wr_txt old_nn) </FONT></P>
<P><FONT face="Arial Unicode MS">; 定义错误处理子程序</FONT></P>
<P><FONT face="Arial Unicode MS">(defun txterr(s)</FONT></P>
<P><FONT face="Arial Unicode MS">(if (and (/= s "console break")</FONT></P>
<P><FONT face="Arial Unicode MS">(/= s "Function cancelled")</FONT></P>
<P><FONT face="Arial Unicode MS">(/= s "quit / exit abort") </FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(princ (strcat "\nError:" s))</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(if olderr (setq *error* olderr)); 恢复原系统设置</FONT></P>
<P><FONT face="Arial Unicode MS">(if oldcmd (setvar "cmdecho" oldcmd))</FONT></P>
<P><FONT face="Arial Unicode MS">(princ)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">; 对话框显示及驱动程序</FONT></P>
<P><FONT face="Arial Unicode MS">(defun diag ( / i)</FONT></P>
<P><FONT face="Arial Unicode MS">(if (> (setq dcl_id (load_dialog "#txt")) 0);加载对话框文件</FONT></P>
<P><FONT face="Arial Unicode MS">(progn</FONT></P>
<P><FONT face="Arial Unicode MS">(if (new_dialog "filetext" dcl id); 显示对话框</FONT></P>
<P><FONT face="Arial Unicode MS">(progn start_list "what");将词组显示到列表框内</FONT></P>
<P><FONT face="Arial Unicode MS">(mapcar 'add_list txt_tb</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(end_list)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq i 1)</FONT></P>
<P><FONT face="Arial Unicode MS">(repeat nn;点取词组分类项后的操作</FONT></P>
<P><FONT face="Arial Unicode MS">(action_tile (strcat "c" (itoa i)) "(wr_txt)")</FONT></P>
<P><FONT face="Arial Unicode MS">(setq i (1+ i))</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(action_tile "what" "(setq i (atoi $value));选中词组</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt (nth i txt_tb))(set_tile \"sel_ok\" txt)"</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(action_tile "sel_ok" "(setq txt $value)")</FONT></P>
<P><FONT face="Arial Unicode MS">(action_tile "accept" "(setq ok T)(done_dialog 1)(unload_dialog dcl_id)")</FONT></P>
<P><FONT face="Arial Unicode MS">(action_tile "cancel" "(unload_dialog dcl_id)")</FONT></P>
<P><FONT face="Arial Unicode MS">(start_dialog)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(prompt "\n无法显示对话框FILETEXT! 请检查对话框内容!")</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(prompt "\n无法加载对话框文件#TXT.DCL! 请检查文件是否存在及路径是否正确!")</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">; 初始化程序, 把第1个分组项中的词组读入表txt_tb中</FONT></P>
<P><FONT face="Arial Unicode MS">(defun init( / fname fp txt1)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq fname (findfile "$txt1.dat"))</FONT></P>
<P><FONT face="Arial Unicode MS">(if (not fname)</FONT></P>
<P><FONT face="Arial Unicode MS">(progn (princ "\n文件 $TXT1.DAT 不存在 !") (exit)) ; 文件不存在, 则退出</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq fp (open fname "r"))</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb '())</FONT></P>
<P><FONT face="Arial Unicode MS">(while (setq txt1 (read_line fp))</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb (cons txt1 txt_tb))</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(close fp)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb (reverse txt_tb))</FONT></P>
<P><FONT face="Arial Unicode MS">(setq old_nn 1);记录索引号</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">; 更换列表框内词组显示内容</FONT></P>
<P><FONT face="Arial Unicode MS">(defun wr_txt ( / fname fname1 fp txt1 i)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq i 1)</FONT></P>
<P><FONT face="Arial Unicode MS">(while (<= i nn); 判别哪个词组项被点中</FONT></P>
<P><FONT face="Arial Unicode MS">(if (= (get_tile (strcat "c" (itoa i))) "1")</FONT></P>
<P><FONT face="Arial Unicode MS">(setq fname1 (strcat "$txt" (itoa i) ".dat")</FONT></P>
<P><FONT face="Arial Unicode MS">i nn</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq i (1+ i))</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(if (setq fname (findfile fname1)); 查找文件是否存在</FONT></P>
<P><FONT face="Arial Unicode MS">(progn</FONT></P>
<P><FONT face="Arial Unicode MS">(setq old_nn (atoi (substr fname1 5)));记录索引号</FONT></P>
<P><FONT face="Arial Unicode MS">(setq fp (open fname "r"))</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb '())</FONT></P>
<P><FONT face="Arial Unicode MS">(while (setq txt1 (read_line fp));依次读出各词组</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb (cons txt1 txt_tb))</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(close fp)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq txt_tb (reverse txt_tb))</FONT></P>
<P><FONT face="Arial Unicode MS">(start_list "what");在列表框内显示词组内容</FONT></P>
<P><FONT face="Arial Unicode MS">(mapcar 'add_list txt_tb)</FONT></P>
<P><FONT face="Arial Unicode MS">(end_list)</FONT></P>
<P><FONT face="Arial Unicode MS">) ; progn</FONT></P>
<P><FONT face="Arial Unicode MS">(progn</FONT></P>
<P><FONT face="Arial Unicode MS">(alert (strcat "文件" fname1 "不存在!"))</FONT></P>
<P><FONT face="Arial Unicode MS">(set_tile (strcat "c" (itoa old_nn)) "1");恢复原记录号</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">) ; if</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">; 主程序开始</FONT></P>
<P><FONT face="Arial Unicode MS">(setq olderr *error* </FONT></P>
<P><FONT face="Arial Unicode MS">*error* txterr</FONT></P>
<P><FONT face="Arial Unicode MS">oldcmd (getvar "cmdecho") </FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(setvar "cmdecho" 0) ; 命令不回显</FONT></P>
<P><FONT face="Arial Unicode MS">(setq nn 9) ; 词组分类数</FONT></P>
<P><FONT face="Arial Unicode MS">(init) ; 初始化</FONT></P>
<P><FONT face="Arial Unicode MS">(diag) ; 驱动对话框</FONT></P>
<P><FONT face="Arial Unicode MS">(if (and ok txt)</FONT></P>
<P><FONT face="Arial Unicode MS">(progn</FONT></P>
<P><FONT face="Arial Unicode MS">(if (or (= (setq sty (tblsearch "STYLE" "HZ")) nil); "HZ"字型是否存在</FONT></P>
<P><FONT face="Arial Unicode MS">(/= (cdr (assoc 40 sty)) 0) ; 字高是否为定值</FONT></P>
<P><FONT face="Arial Unicode MS">(/=(getvar "TEXTSTYLE") "HZ"); 当前字型是否为"HZ" </FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(command "STYLE" "HZ" "txt,hztxt" 0 0.7 0 "n" "n") ; 设置"HZ"字型</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(initget (+ 2 4));下面的输入值要求大于0</FONT></P>
<P><FONT face="Arial Unicode MS">(setq ht (getreal "\n请输入字高<500>:"))</FONT></P>
<P><FONT face="Arial Unicode MS">(if (not ht) (setq ht 500))</FONT></P>
<P><FONT face="Arial Unicode MS">(setq pt (getpoint "\n请点取文字起点:"))</FONT></P>
<P><FONT face="Arial Unicode MS">(command "text" pt ht 0 txt)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">(setq *error* olderr);恢复原设置</FONT></P>
<P><FONT face="Arial Unicode MS">(setvar "cmdecho" oldcmd)</FONT></P>
<P><FONT face="Arial Unicode MS">(princ)</FONT></P>
<P><FONT face="Arial Unicode MS">)</FONT></P>
<P><FONT face="Arial Unicode MS">// #txt.dcl </FONT></P>
<P><FONT face="Arial Unicode MS">// 供#txt.lsp调用</FONT></P>
<P><FONT face="Arial Unicode MS">filetext : dialog { // 对话框名称</FONT></P>
<P><FONT face="Arial Unicode MS">label = "常用词组"; // 对话框标识</FONT></P>
<P><FONT face="Arial Unicode MS">: row {</FONT></P>
<P><FONT face="Arial Unicode MS">: boxed_column {</FONT></P>
<P><FONT face="Arial Unicode MS">label = " 索 引 ";</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "常用术语"; // 多选一按钮</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c1";</FONT></P>
<P><FONT face="Arial Unicode MS">value = "1"; // 初始值为"1", 表示选中</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "图纸名称";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c2";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "房间名称";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c3";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "卫生器具";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c4";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "管材配件";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c5";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "器材仪表";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c6";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "常用设备";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c7";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "构筑物";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c8";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: radio_button {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "其它";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "c9";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">: list_box {</FONT></P>
<P><FONT face="Arial Unicode MS">label = "词组内容";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "what";</FONT></P>
<P><FONT face="Arial Unicode MS">height = 15;</FONT></P>
<P><FONT face="Arial Unicode MS">width = 26;</FONT></P>
<P><FONT face="Arial Unicode MS">allow_accept = true; // 可双击鼠标选取</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">spacer_1;</FONT></P>
<P><FONT face="Arial Unicode MS">: edit_box {// 编辑框</FONT></P>
<P><FONT face="Arial Unicode MS">label = "所选词组:";</FONT></P>
<P><FONT face="Arial Unicode MS">key = "sel_ok";</FONT></P>
<P><FONT face="Arial Unicode MS">}</FONT></P>
<P><FONT face="Arial Unicode MS">spacer_1;// 增加间距</FONT></P>
<P><FONT face="Arial Unicode MS">ok_cancel;</FONT></P>
<P><FONT face="Times New Roman">}</FONT></P> 就是啊,有点过于专业了,能不能浅显易懂的讲解一下,谢谢 有点过于专业了,能不能浅显易懂的讲解一下 程序设计专用词汇。使用者不用看 这个不太懂,如果解决完,可以共同探讨一下吗? 不太懂啊············· 有对话框,挺高级的,不过这是机械社区,楼主是搞建筑滴:lol 这个很专业啊。。。。谢谢!
页:
[1]