lisp怎么获取dcl的key值?(已解决)
本帖最后由 陈鱼儿 于 2023-12-7 13:36 编辑dcl里有个编辑框,想要输入编辑框,在把值给到梨lisp的代码,望大佬指点迷津
以下为lisp代码:
(defun sr2 ()
(setq in(atoi(get_tile "srsz")))
)
(defun sr ()
(setq dcl_id (load_dialog "my_dialog"))
(if(< dcl_id 0)(exit))
(if(not(new_dialog "a0" dcl_id))(exit))
(action_tile "accept" "(sr2)(done_dialog 1)")
(setq dd(start_dialog))
(unload_dialog my_dialog)
)
以下为dcl代码:
a0:dialog {
label = "示例对话框";
:row {
:edit_box {
label = "输入数值:";
key = "srsz";
edit_width = 20;
}
}
spacer_1; //空白一行
ok_cancel;
}
获取对话框数值示例代码:read 读取数值
;以下为对话框程序自动生成:
(defun ngc-dcl()
(setq dcl_file (vl-filename-mktemp nil nil ".dcl"))
(setq f_dcl (open dcl_file "w"))
;;下面的对话框名称ngc,和下面的对应,可以改成自己的名称,要上下对应:
(write-line "ngc:dialog {" f_dcl)
(write-line " label = \"春蝉可视化\" ;" f_dcl)
(write-line " :edit_box {" f_dcl)
(write-line " edit_width = 20 ;" f_dcl)
(write-line " key = \"srsz\" ;" f_dcl)
(write-line " label = \"圆的半径\" ;" f_dcl)
(write-line " }" f_dcl)
(write-line " ok_cancel;" f_dcl)
(write-line "}" f_dcl)
(close f_dcl)dcl_file)
;;主程序开始:-------------------------------
(defun c:tt ()
(setvar "cmdecho" 0) ;_关闭命令提示
(setq osmode_bak (getvar "osmode")) ;_记录捕捉
(setvar "osmode" 0) ;_关闭捕捉
(setq dcl_id (load_dialog (setq dcl_file (ngc-dcl))));;对话框加载
(vl-file-delete dcl_file);;加载后删除dcl文件
(setq chk 0);;设置关键联动默认变量为0
(new_dialog "ngc" dcl_id);;此处为对话框名称ngc,和上面对应,要上下对应
(setq keys '("srsz" "accept" "cancel"));对话框key值列表
(foreach key keys (if (eval (read (strcat key "_bak"))) (set_tile key (eval (read (strcat key "_bak"))))))
(action_tile "accept" "(setq chk 1)(备份数据)(done_dialog 1)");;确定按钮动作关联
(start_dialog)
(读取对话框数据);;此处为读取对话框数据的地方
(unload_dialog dcl_id)
(运行程序);;此处为主要程序运行
(setvar "osmode" osmode_bak) ;_还原捕捉
(setvar "cmdecho" 1) ;_打开命令提示
(princ))
(defun 读取对话框数据 ()
(setq t1 (read srsz_bak)))
(defun 备份数据( / key)(foreach key keys (set (read (strcat key "_bak")) (get_tile key))))
(defun 运行程序 ()
(if (= chk 1) ;;此处为自定义条件和执行,可以改成其他的关联方式
(command "circle" (getpoint) t1)))
;;程序结束-----------------------------------
直接复制或者下载,代码一样。
shcvip 发表于 2023-11-28 19:29
如果是二行输入需要输入,那上面的DCL怎么写啊
;以下为对话框程序自动生成:
(defun ngc-dcl()
(setq dcl_file (vl-filename-mktemp nil nil ".dcl"))
(setq f_dcl (open dcl_file "w"))
;;下面的对话框名称ngc,和下面的对应,可以改成自己的名称,要上下对应:
(write-line "ngc:dialog {" f_dcl)
(write-line " label = \"春蝉可视化\" ;" f_dcl)
(write-line " :edit_box {" f_dcl)
(write-line " edit_width = 20 ;" f_dcl)
(write-line " key = \"srsz1\" ;" f_dcl)
(write-line " label = \"圆的半径1\" ;" f_dcl)
(write-line " }" f_dcl)
(write-line " :edit_box {" f_dcl)
(write-line " edit_width = 20 ;" f_dcl)
(write-line " key = \"srsz2\" ;" f_dcl)
(write-line " label = \"圆的半径2\" ;" f_dcl)
(write-line " }" f_dcl)
(write-line " ok_cancel;" f_dcl)
(write-line "}" f_dcl)
(close f_dcl)dcl_file)
;;主程序开始:-------------------------------
(defun c:tt ()
(setvar "cmdecho" 0) ;_关闭命令提示
(setq osmode_bak (getvar "osmode")) ;_记录捕捉
(setvar "osmode" 0) ;_关闭捕捉
(setq dcl_id (load_dialog (setq dcl_file (ngc-dcl))));;对话框加载
(vl-file-delete dcl_file);;加载后删除dcl文件
(setq chk 0);;设置关键联动默认变量为0
(new_dialog "ngc" dcl_id);;此处为对话框名称ngc,和上面对应,要上下对应
(setq keys '("srsz1" "srsz2" "accept" "cancel"));对话框key值列表
(foreach key keys (if (eval (read (strcat key "_bak"))) (set_tile key (eval (read (strcat key "_bak"))))))
(action_tile "accept" "(setq chk 1)(备份数据)(done_dialog 1)");;确定按钮动作关联
(start_dialog)
(读取对话框数据);;此处为读取对话框数据的地方
(unload_dialog dcl_id)
(运行程序);;此处为主要程序运行
(setvar "osmode" osmode_bak) ;_还原捕捉
(setvar "cmdecho" 1) ;_打开命令提示
(princ))
(defun 读取对话框数据 ()
(setq t1 (read srsz1_bak)
t2 (read srsz2_bak))
)
(defun 备份数据( / key)(foreach key keys (set (read (strcat key "_bak")) (get_tile key))))
(defun 运行程序 ()
(if (= chk 1) ;;此处为自定义条件和执行,可以改成其他的关联方式
(progn
(setq pt (getpoint "\n指定圆心画同心圆"))
(command "circle" pt t1)
(command "circle" pt t2)
))
)
;;程序结束-----------------------------------
在实务上个人倾向用dos_editbox
(dos_editbox title prompt ) 本帖最后由 ljfdjjj 于 2023-11-28 08:55 编辑
不用搞子程序,我在群里教过你的,一句话就能搞定。当然你这样写也可以,不过你的这句 (unload_dialog my_dialog)错了,后面的参数不是DCL的文件名,而是DCL文件的id。也就是你前面赋值的那个变量:dcl_id,所以这句应该这么写(unload_dialog dcl_id)。再给你看下我教你的那种写法(defun c:sr()
(setq dcl_id (load_dialog "my_dialog"))
(if(< dcl_id 0)(exit))
(if(not(new_dialog "a0" dcl_id))(exit))
(action_tile "accept" "(setq in(atoi(get_tile \"srsz\")))(done_dialog 1)")
(start_dialog)
(unload_dialog dcl_id)
(alert(strcat"你输入的数值是"(itoa in)))
) 只输入一个。直接用(lisped "缺省值")就行了,没必要折腾DCL kozmosovia 发表于 2023-11-28 09:51
只输入一个。直接用(lisped "缺省值")就行了,没必要折腾DCL
大佬 我刚才试了一下,那个全屏编辑是啥啊 感谢大佬分享 hhh454 发表于 2023-11-27 19:25
获取对话框数值示例代码:read 读取数值
如果是二行输入需要输入,那上面的DCL怎么写啊 hhh454 发表于 2023-11-28 23:03
如果对话框,弹出来的时候,就给他一个默认值,这个更完美了。
页:
[1]
2