第一次学习写对话框,有些问题需要帮助!
初次学习写DCL对话框,学写一个符号插入工具,遇到了几个问题:
1、索引页码和索引图号第一次打开对话框赋值后,下来每次打开怎样保持先一次的值?
2、比例那里能不能只输入数字,输入其他值弹出非法对话框并继续返回当前对话框进行修改;
以下为源码:
lmfh.DCLlmfh : dialog {
label = "立面符号插入工具——by凯 凯";
: row {
: boxed_column {
: edit_box {
label = "索引页码:";
key = "syym_sc";
edit_width = 15;
edit_limit =15;
fixed_width = true;
}
: edit_box {
label = "索引图号:";
key = "syh_sc";
edit_width = 15;
edit_limit =15;
fixed_width = true;
}
: edit_box {
label = "当前比例:";
key = "bl_sc";
edit_width = 15;
edit_limit =15;
fixed_width = true;
}
}
: boxed_column {
:image {
key = "lmimage";
width = 15;
height = 7;
fixed_width = true;
fixed_height = true;
color = -2;
allow_accept=true;
}
}
}
: row {
alignment=centered;
fixed_width=true;
: button {
label = "确定";
key = "ins_ok";
width = 8;
}
: spacer { width =2;}
cancel_button;
}
}lisp文件;;;立面符号插入命令,作者:凯凯
(defun c:s1q (/ lst ptt1 pt1 n1 n2 n8 n2 keyk keyp fh_layer)
(command "undo" "be")
(command"ATTDIA" 0)
(dcl_lmfh)
(command "undo" "e")
(princ)
)
(defun dcl_lmfh ()
(setq dcl_id (load_dialog "lmfh"))
(new_dialog "lmfh" dcl_id)
(setq zs_err 1)
(set_tile "bl_sc" (rtos (getvar "DIMSCALE")))
(set_tile "syym_sc" "索引页码");;;设置引页码为-
(set_tile "syh_sc" "索引号") ;;;设置索引号1
(setq key "lmimage")
(setq px (dimx_tile key))
(setq py (dimy_tile key))
(start_image key)
(fill_image 0 0 px py -2)
(slide_image 0 0 px py "lmfh")
(action_tile "ins_ok" "(ok_lmfh) (done_dialog 1) ")
(setq dd (start_dialog)) (UNLOAD_DIALOG dcl_id)
(if (= dd 1)
(progn
(setq pt1 (getpoint "\n指定立面符号插入点:"))
(if (= pt1 nil)
(setq pt1 (getpoint "\n*错误*,请指定立面符号插入点或按ESC键结束命令:"))
)
(if (not (tblsearch "block" "立面图号")) ;;判断是否存在"立面图号"图块,无则创建。
(command "INSERT" "klimianp" "0.0" 1 1 0)
)
(command "layer" "s" fh_layer "")
(if (= err 1)
(princ "立面图号未插入")
(command "INSERT" "立面图号" pt1 n1 n1 "" keyk keyp))
)
)
)
(defun ok_lmfh ()
(setq n1 (get_tile "bl_sc"));;;当前标注比例
(if (= n1 "")
(setq n1 n2)
(setq n1 n1)
)
(setq keyk (get_tile "syym_sc")) ;;;;;请输入索引页码,如D-01,D-02,D-03.
(if (= keyk "")
(setq keyk "索引页码")
)
(setq keyp (get_tile "syh_sc")) ;;;;; 请输入索引号,如1,2,3... A,B,C...<1>:
(if (= keyp "")
(setq keyp "索引号")
)
) 使用一个全局参数记忆你的选择
也可以采用外部文件或setcfg等方式
dcl中文本控件功能比较弱
必须另加判断以及格式转换的代码 2、比例那里能不能只输入数字,输入其他值弹出非法对话框并继续返回当前对话框进行修改;继续问 文本控件只接受文字
并不会自动转换成你需要的格式
所以你必须进行转换
转换前必须校验输入的字符串
是否符合你的需要
并不需要在错误输入时弹出错误对话框
这会让你的程序显得不是那么友好
可以设置一个text_part控件
数值错误时显示错误提示
同时也可以临时禁止accept
直到输入正确的数值
(action_tile "bl_sc" "(比例校验 $value)")
(defun 比例校验(v)
;1.是否数字字符串
;2.是否正整数
;3.是否....
(.........)
(if ok
(progn
(mode_title "accept" 0)
(set_tile "警告" "")
(setq n1 v)
)
(progn
(mode_title "accept" 1)
(set_tile "警告" "输入错误,必须为正整数")
(setq n1 nil)
)
) lmfh:dialog{
label="立面符号插入工具——by 凯 凯";
:row{
:boxed_column{
:edit_box{
label="索引页码:";
key="syym_sc";
edit_width=15;
edit_limit=15;
fixed_width=true;
}
:edit_box{
label="索引图号:";
key="syh_sc";
edit_width=15;
edit_limit=15;
fixed_width=true;
}
:edit_box{
label="当前比例:";
key="bl_sc";
edit_width=15;
edit_limit=15;
fixed_width=true;
}
}
:boxed_column{
:image{
key="lmimage";
width=15;
height=7;
fixed_width=true;
fixed_height=true;
color=-2;
allow_accept=true;
}
}
}
ok_cancel;
}
;;;立面符号插入命令,作者:凯凯
(defun c:s1q (/ lst ptt1 pt1 n1 n2 n8 n2 keyk keyp fh_layer)
(command "undo" "be")
(command"ATTDIA" 0)
(dcl_lmfh)
(command "undo" "e")
(princ)
)
(defun dcl_lmfh ()
(if (> (setq dcl_id (load_dialog "lmfh")) 0) (progn
(if (new_dialog "lmfh" dcl_id) (progn
(setq key "lmimage")
(setq px (dimx_tile key))
(setq py (dimy_tile key))
(start_image key)
(fill_image 0 0 px py -2)
(slide_image 0 0 px py "lmfh")
(end_image)
(setq zs_err 1)
(set_tile "bl_sc" (rtos (getvar "DIMSCALE")))
(if (and (= (type keyk) 'STR) (> (strlen keyk) 0))
(set_tile "syym_sc" keyk)
(set_tile "syym_sc" "索引页码") ;;;设置索引页码1
)
(if (and (= (type keyp) 'STR) (> (strlen keyp) 0))
(set_tile "syh_sc" keyp)
(set_tile "syh_sc" "索引号") ;;;设置索引号1
)
(action_tile "bl_sc" "(testbl)")
(action_tile "cancel" "(done_dialog 0)")
(action_tile "accept" "(ok_lmfh) (done_dialog 1)")
(setq dd (start_dialog))
)
(princ "\n无法显示对话框!")
)
(unload_dialog dcl_id)
)
(princ "\n无法加载对话框!")
)
(if (= dd 1) (progn
(while (= (setq pt1 (getpoint "\n指定立面符号插入点:")) nil)
(princ "\n*错误*,请指定立面符号插入点或按ESC键结束命令:")
)
(if (not (tblsearch "block" "立面图号")) ;;判断是否存在"立面图号"图块,无则创建。
(command "INSERT" "klimianp" "0.0" 1 1 0)
)
(command "layer" "s" fh_layer "")
(if (= err 1)
(princ "立面图号未插入")
(command "INSERT" "立面图号" pt1 n1 n1 "" keyk keyp)
)
))
)
(defun testbl ()
(setq n1 (get_tile "bl_sc"))
(if (= (rtos n1 2) 0) (set_tile "bl_sc" (rtos (getvar "DIMSCALE") 2)))
)
(defun ok_lmfh ()
(setq n1 (get_tile "bl_sc"));;;当前标注比例
(if (= n1 "") (setq n1 n2))
(setq keyk (get_tile "syym_sc")) ;;;;;请输入索引页码,如D-01,D-02,D-03.
(if (= keyk "") (setq keyk "索引页码"))
(setq keyp (get_tile "syh_sc")) ;;;;; 请输入索引号,如1,2,3... A,B,C...<1>:
(if (= keyp "") (setq keyp "索引号"))
)
谢谢!问题已经解决!
页:
[1]