对话框如何输入字符串并将其转换成变量进行赋值呢
大家好,之前一个社区大佬帮忙写了一个对话框代码,我后面的程序都是在此代码的基础上进行对话框编辑的,但是我发现这个对话框有限制,就是只能输入数字,输入字符串(字母或者其他符号等)就不能用了,求大佬帮我改一下下面的代码,让其无论输入数字或者字符串都能赋予值的变量(defun c:ss (/ d1 d2 pt0 d3)
(setvar "cmdecho" 0) ;关闭普通命令提示信息
(setvar "osmode" 0);关闭对象捕捉状态
(command "._undo" "_begin")
(setq Keys '("d1" "d2" "d3" ))
(if (not bhd4)
(progn
(setq bhd1 1 bhd2 1 bhd3 150)
)) ;设变量初值
;加载DCL对话框
(setq DcLwjm (make_ZDBH_dcl)) ;生成DCL对话框
(setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框
;激活DCL画面
(if (not (new_dialog "自动编号" dcl_id))
(exit)
)
;控件赋初值
(mapcar '(lambda(Key Val) (set_tile Key Val))
Keys
(list
(rtos bhd1 2 2)
(rtos bhd2 2 2)
(rtos bhd3 2 2)
)
)
;设置d1为焦点
(mode_tile "d1" 2)
;控件相关操作
(foreach Key Keys
(action_tile Key "(set (read (strcat \"bh\" $key)) (atof (get_tile $key)))
"
)
)
(action_tile "accept" "(done_dialog 1)")
;将控制权交给DCL
(setq do_what (start_dialog))
;终止DCL: (done_dialog 0) (done_dialog 1)
(cond ((= do_what 0)
(princ "\n单击了取消按钮")
)
((= do_what 1)
(princ "\n单击了确定按钮")
; 这里加入进行相应的处理部分
用你的套不习惯,用我习惯的重新套了一遍
代码不完整,,少了bh4的获取 yaojing38 发表于 2023-4-7 09:28
代码不完整,,少了bh4的获取
我知道,BH4只是我用来测试的,可以替换bhd1,bhd2,我现在的疑惑是如果把bhd1改成字符串“1/” "deh-"之类的就会运行出错 开头的部分,替换一下试试 ,之后的不动
(defun c:ss (/ d1 d2 pt0 d3)
(setvar "cmdecho" 0) ;关闭普通命令提示信息
(setvar "osmode" 0);关闭对象捕捉状态
(command "._undo" "_begin")
(setq Keys '("d1" "d2" "d3" ))
(if (not bhd4)
(progn
(setq bhd1 "1" bhd2 "1" bhd3 "150")
)) ;设变量初值
;加载DCL对话框
(setq DcLwjm (make_ZDBH_dcl)) ;生成DCL对话框
(setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框
;激活DCL画面
(if (not (new_dialog "自动编号" dcl_id))
(exit)
)
;控件赋初值
(mapcar
'(lambda(Key Val) (set_tile Key Val))
Keys
(list bhd1 bhd2 bhd3)
)
xj6019 发表于 2023-4-7 10:38
开头的部分,替换一下试试 ,之后的不动
(defun c:ss (/ d1 d2 pt0 d3)
(setvar "cmdecho" 0) ;关闭普 ...
到最后一步还是有问题,显示文字出错,因为我只需要前缀带有字符串,其他都是正常的文字,所以在你的基础上稍微改了一下,最后还是不行大佬有空帮忙看看什么问题,下面是完整代码
(defun make_ZDBH_dcl (/ lst_str str file f)
(setq lst_str
(list
"自动编号:dialog { //定义名字为自动编号的对话框"
" label= \"自动编号\";//显示在对话框顶部的标签"
" :row{ //引用行"
" :edit_box{ //引用编辑框1"
" label=\"编号前缀为: \"; //编辑框1的标签"
" edit_width=8; //编辑框1的宽度"
" key= \"d1\";//编辑框1的关键字"
" mnemonic = \"d1\";//编辑框1的热键"
" }} //编辑框1引用结束"
" :row{ //引用行"
" :edit_box{ //引用编辑框1"
" label=\"起始数字为: \"; //编辑框1的标签"
" edit_width=8; //编辑框1的宽度"
" key= \"d2\";//编辑框1的关键字"
" mnemonic = \"d2\";//编辑框1的热键"
" }} //编辑框1引用结束"
" :row{ //引用行"
" :edit_box{ //引用编辑框1"
" label=\"编号大小为: \"; //编辑框1的标签"
" edit_width=8; //编辑框1的宽度"
" key= \"d3\";//编辑框1的关键字"
" }} //编辑框1引用结束"
" ok_cancel;// 引用ok_cancel组合控件"
"}"
)
)
(setq file (vl-filename-mktemp "DclTemp-ZDBH.dcl"))
(setq fff (open file "w"))
(foreach str lst_str
(write-line str fff)
)
(close fff)
file
)
(defun c:ss (/ d1 d2 pt0 d3)
(setvar "cmdecho" 0) ;关闭普通命令提示信息
(setvar "osmode" 0);关闭对象捕捉状态
(command "._undo" "_begin")
(setq Keys '("d1" "d2" "d3" ))
(if (not bhd4)
(progn
(setq bhd1 "1/" bhd2 1 bhd3 150)
)) ;设变量初值
;加载DCL对话框
(setq DcLwjm (make_ZDBH_dcl)) ;生成DCL对话框
(setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框
;激活DCL画面
(if (not (new_dialog "自动编号" dcl_id))
(exit)
)
;控件赋初值
(mapcar
'(lambda(Key Val) (set_tile Key Val))
Keys
(list bhd1
(rtos bhd2 2 2)
(rtos bhd3 2 2))
)
;设置d1为焦点
(mode_tile "d1" 2)
;控件相关操作
(foreach Key Keys
(action_tile Key "(set (read (strcat \"bh\" $key)) (atof (get_tile $key)))
"
)
)
(action_tile "accept" "(done_dialog 1)")
;将控制权交给DCL
(setq do_what (start_dialog))
;终止DCL: (done_dialog 0) (done_dialog 1)
(cond ((= do_what 0)
(princ "\n单击了取消按钮")
)
((= do_what 1)
(princ "\n单击了确定按钮")
; 这里加入进行相应的处理部分
(while (< bhd2 9999)
(progn
(setq pt0 (getpoint "\n请选择插入点: "))
(if (null pt0) (exit))
(setq d2s( rtos bhd2 2 2))
(command "color" 1)
(command "text" "m" pt0 bhd3 0 (strcat bhd1d2s))
(setq bhd2 (1+ bhd2))
(command "color" 7)))
))
(setvar "osmode" 16383);打开对象捕捉状态
(princ) ;静默退出
(command "._undo" "_end")
) 本帖最后由 yaojing38 于 2023-4-7 12:15 编辑
;控件相关操作
(foreach Key Keys
(action_tile Key "(set (read (strcat "bh" $key)) (atof (get_tile $key)))
"
)
)
;替换
(action_tile "d1" "(set (read (strcat "bh" $key)) (read(get_tile $key)))")
(action_tile "d2" "(set (read (strcat "bh" $key)) (atof (get_tile $key)))")
(action_tile "d3" "(set (read (strcat "bh" $key)) (atof (get_tile $key)))") xj6019 发表于 2023-4-7 08:27
用你的套不习惯,用我习惯的重新套了一遍
谢谢大佬,学习了 yaojing38 发表于 2023-4-7 12:04
;控件相关操作
(foreach Key Keys
(action_tile Key "(set (read (strcat "bh" $key)) ( ...
试了,显示参数太多 xj6019 发表于 2023-4-7 08:27
用你的套不习惯,用我习惯的重新套了一遍
不好意思,弱弱的问下,能否不结束程序鼠标右键重新显示对话框继续运行?
页:
[1]