Dcl列表框帮助
我在一个文件中有3个lisp例程例如
(defun c:demo1()……………………)
(defun c:demo2()……………………)
(defun c:demo3()……………………)
如何创建一个简单的对话框,在一个列表框中包含3个lisp例程和两个按钮(确定和取消)?
我希望每次我从列表框中选择,例如demo2,然后按OK,“demo2”lisp例程开始运行。。。
对不起,我英语不好。。 对于这么简单的事情,似乎需要做很多的腿部工作。
为什么不在命令行上进行选择?
(initget 0 "1 2 3")
(setq demo (getkword "\nSpecify demo number : "))
试试这个,
确保将两个文件放在一起,并且位于ACAD支持搜索路径中。
只需键入演示。
演示。dcl
/////////////////////////////////////////////////////////////////////////////////////////////
DEMO : dialog {
label = "Demo.lsp";
: column {
: boxed_column {
label = "Select a function:";
: popup_list {
key = "FUNCT";
width = 18.0;
fixed_width = true;
alignment = centered;
}
: spacer {
height = 0;
}
}
: button {
label = "&Ok";
key = "accept";
width = 18;
fixed_width = true;
alignment = centered;
is_default = true;
}
: button {
label = "&Exit";
key = "cancel";
width = 18;
fixed_width = true;
alignment = centered;
is_cancel = true;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
演示。lsp
(defun C:DEMO (/ DCL_ID FUNCT FUNCT_LIST)
(or F:UNCT (setq F:UNCT 0))
(setq FUNCT_LIST (list "Demo 1" "Demo 2" "Demo 3"))
(setq DCL_ID (load_dialog "DEMO.dcl"))
(if (not (new_dialog "DEMO" DCL_ID))
(exit))
(start_list "FUNCT")(mapcar 'add_list FUNCT_LIST)(end_list)
(if F:UNCT-DEF (set_tile "FUNCT" (itoa F:UNCT-DEF)))
(action_tile "accept"
(strcat
"(progn (setq F:UNCT (atoi (get_tile \"FUNCT\")) F:UNCT-DEF F:UNCT)"
"(done_dialog)(setq button T))"))
(action_tile "cancel" "(done_dialog)(setq button nil)")
(start_dialog)
(unload_dialog DCL_ID)
(setq FUNCT F:UNCT)
(if button
(cond
((= FUNCT 0)(ALERT "You selected Demo 1"))
((= FUNCT 1)(ALERT "You selected Demo 2"))
((= FUNCT 2)(ALERT "You selected Demo 3"))))
(princ))
如果我想在命令行上这样做,我可以简单地写:demo1或demo2或。。。。。
秃鹰
我想这很好。
我可以“放”这个演示吗。演示中的dcl文件。lsp? 但是您仍然需要调用函数来加载List_框-这有什么意义? 它是哪一个?
你想要一个对话吗?还是要从命令提示符下运行? 但我更喜欢这样
(initget "1 2 3")
(setq demo (getkword "\nSpecify demo number <1>: ")) 如果您将其编译为FAS快速加载文件,那么是的。
或者它需要以不同的方式写入lisp。
我更喜欢上面的方法。 我可能会这样做
(defun c:demo (/ dcl_write DATA DC FLAG PTR)
(vl-load-com)
(setq data '(("demo1" . (c:demo1))
("demo2" . (c:demo2))
("demo3" . (c:demo3))))
(defun dcl_write (fname / wPath ofile)
(if (not (findfile fname))
(if (setq wPath (findfile "ACAD.PAT"))
(progn
(setq wPath (vl-filename-directory wPath))
(or (eq "\\" (substr wPath (strlen wPath)))
(setq wPath (strcat wPath "\\")))
(setq ofile (open (strcat wPath fname) "w"))
(foreach str '("demo : dialog { label = \"Select Function\"; spacer;"
" : list_box { key = \"lst\"; } spacer;ok_cancel; }" )
(write-line str ofile)) (setq ofile (close ofile)) t)
nil)
t))
(defun Make_list (key lst)
(start_list key)
(mapcar (function add_list) lst) (end_list))
(cond ((not (dcl_write "LMAC_demo.dcl"))
(princ "\n** DCL could not be written **"))
((<= (setq dc (load_dialog "LMAC_demo.dcl")) 0)
(princ "\n** DCL File not Found **"))
((not (new_dialog "demo" dc))
(princ "\** Dialog Could not be Loaded **"))
(t (Make_list "lst" (mapcar (function car) data))
(setq ptr (set_tile "lst" "0"))
(action_tile "lst" "(setq ptr $value)")
(setq flag (start_dialog) dc (unload_dialog dc))
(if (= 1 flag) (eval (cdr (nth (atoi ptr) data))))))
(princ))
然后它将转到其受人尊重的功能。
Local Functions
(cond
((= FUNCT 0)(DEMO1))
((= FUNCT 1)(DEMO2))
((= FUNCT 2)(DEMO3)))
or
Global Functions
(cond
((= FUNCT 0)(C:DEMO1))
((= FUNCT 1)(C:DEMO2))
((= FUNCT 2)(C:DEMO3)))
谢谢
在李的方法中,我如何更改标签的“名称”?
选择功能?
页:
[1]
2