玩软件 > AutoCAD
+

AutoCAD内常用术语的自动标注方法(2)

2022-02-12    作者:未知    来源:


本程序在AutoCAD R12.0 FOR DOS及FOR WINDOWS版上均调试通过。
(defun c:#txt ( / oldcmd olderr ok txt_tb txt dcl_id sty fp nn ht pt txterr diag init wr_txt old_nn)
; 定义错误处理子程序
(defun txterr(s)
(if (and (/= s "console break")
(/= s "Function cancelled")
(/= s "quit / exit abort")
)
(princ (strcat "\nError:" s))
)
(if olderr (setq *error* olderr)); 恢复原系统设置
(if oldcmd (setvar "cmdecho" oldcmd))
(princ)
)
; 对话框显示及驱动程序
(defun diag ( / i)
(if (> (setq dcl_id (load_dialog "#txt")) 0);加载对话框文件
(progn
(if (new_dialog "filetext" dcl [JX*6]id); 显示对话框
(progn start_list "what");将词组显示到列表框内
(mapcar 'add_list txt_tb
)
(end_list)
(setq i 1)
(repeat nn;点取词组分类项后的操作
(action_tile (strcat "c" (itoa i)) "(wr_txt)")
(setq i (1+ i))
)
(action_tile "what" "(setq i (atoi $value));选中词组
(setq txt (nth i txt_tb))(set_tile \"sel_ok\" txt)"
)
(action_tile "sel_ok" "(setq txt $value)")
(action_tile "accept" "(setq ok T)(done_dialog 1)(unload_dialog dcl_id)")
(action_tile "cancel" "(unload_dialog dcl_id)")
(start_dialog)
)
(prompt "\n无法显示对话框FILETEXT! 请检查对话框内容!")
)
)
(prompt "\n无法加载对话框文件#TXT.DCL! 请检查文件是否存在及路径是否正确!")
)
)
; 初始化程序, 把第1个分组项中的词组读入表txt_tb中
(defun init( / fname fp txt1)
(setq fname (findfile "$txt1.dat"))
(if (not fname)
(progn (princ "\n文件 $TXT1.DAT 不存在 !") (exit)) ; 文件不存在, 则退出
)
(setq fp (open fname "r"))
(setq txt_tb '())
(while (setq txt1 (read_line fp))
(setq txt_tb (cons txt1 txt_tb))
)
(close fp)
(setq txt_tb (reverse txt_tb))
(setq old_nn 1);记录索引号
)
; 更换列表框内词组显示内容
(defun wr_txt ( / fname fname1 fp txt1 i)
(setq i 1)
(while (<= i nn); 判别哪个词组项被点中
(if (= (get_tile (strcat "c" (itoa i))) "1")
(setq fname1 (strcat "$txt" (itoa i) ".dat")
i nn
)
)
(setq i (1+ i))
)
(if (setq fname (findfile fname1)); 查找文件是否存在
(progn
(setq old_nn (atoi (substr fname1 5)));记录索引号
(setq fp (open fname "r"))
(setq txt_tb '())
(while (setq txt1 (read_line fp));依次读出各词组
(setq txt_tb (cons txt1 txt_tb))
)
(close fp)
(setq txt_tb (reverse txt_tb))
(start_list "what");在列表框内显示词组内容
(mapcar 'add_list txt_tb)
(end_list)
) ; progn
(progn
(alert (strcat "文件" fname1 "不存在!"))
(set_tile (strcat "c" (itoa old_nn)) "1");恢复原记录号
)
) ; if
)
; 主程序开始
(setq olderr *error*
*error* txterr
oldcmd (getvar "cmdecho")
)
(setvar "cmdecho" 0) ; 命令不回显
(setq nn 9) ; 词组分类数
(init) ; 初始化
(diag) ; 驱动对话框
(if (and ok txt)
(progn
(if (or (= (setq sty (tblsearch "STYLE" "HZ")) nil); "HZ"字型是否存在
(/= (cdr (assoc 40 sty)) 0) ; 字高是否为定值
(/=(getvar "TEXTSTYLE") "HZ"); 当前字型是否为"HZ"
)
(command "STYLE" "HZ" "txt,hztxt" 0 0.7 0 "n" "n") ; 设置"HZ"字型
)
(initget (+ 2 4));下面的输入值要求大于0
(setq ht (getreal "\n请输入字高<500>:"))
(if (not ht) (setq ht 500))
(setq pt (getpoint "\n请点取文字起点:"))
(command "text" pt ht 0 txt)
)
)
(setq *error* olderr);恢复原设置
(setvar "cmdecho" oldcmd)
(princ)
)
// #txt.dcl
// 供#txt.lsp调用
filetext : dialog { // 对话框名称
label = "常用词组"; // 对话框标识
: row {
: boxed_column {
label = " 索 引 ";
: radio_button {
label = "常用术语"; // 多选一按钮
key = "c1";
value = "1"; // 初始值为"1", 表示选中
}
: radio_button {
label = "图纸名称";
key = "c2";
}
: radio_button {
label = "房间名称";
key = "c3";
}
: radio_button {
label = "卫生器具";
key = "c4";
}
: radio_button {
label = "管材配件";
key = "c5";
}
: radio_button {
label = "器材仪表";
key = "c6";
}
: radio_button {
label = "常用设备";
key = "c7";
}
: radio_button {
label = "构筑物";
key = "c8";
}
: radio_button {
label = "其它";
key = "c9";
}
}
: list_box {
label = "词组内容";
key = "what";
height = 15;
width = 26;
allow_accept = true; // 可双击鼠标选取
}
}
spacer_1;
: edit_box {// 编辑框
label = "所选词组:";
key = "sel_ok";
}
spacer_1;// 增加间距
ok_cancel;
}

阅读:980    评论:0
  • 相关文章
  • 热门文章
  • 相关评论
网站地图

免责申明:我要玩起网旨在提供一个相互学习交流的平台,是一个完全免费的网站,部分原创作品,欢迎转载,部分内容来自互联网,如果侵犯了您的权利请尽快通知我们!邮箱:279459762@qq.com Copyright 2018-2021我要玩起网

  湘ICP备17006802号-2
【电脑版】  【回到顶部】