jonathann3891 发表于 2022-7-5 18:41:28

带提示帮助的Lisp

我试图创建一个简单的lisp,它将显示一个弹出菜单,用户将选择一个绘图大小。
 
我有流行菜单。我只是不知道如何调用选择,无论我在谷歌上搜索什么,我都找不到任何东西。
 
有人能给我指一下正确的方向吗?
 
(defun c:test ()
(initget 1 "11x17 PDF 22x34")
(setq psize (getkword (strcat "\nSelect Plot :"))))

rlx 发表于 2022-7-5 18:48:38

RLXls。LSP
 
在该lisp中,您可以从xls中进行选择,然后将其粘贴到autocad中,您将发现一个名为RLXLs\u-Kul的函数。此函数将列表作为参数,并允许您选择其中一项。我不知道你的技能水平,但我希望其中的一些代码会对你有所帮助。
 
顺便说一句,kul是荷兰语,意思是“kies uit lijst”,可以翻译成“choose from list”,别忘了dcl部分。。。
 
gr.Rlx

BIGAL 发表于 2022-7-5 18:55:19

另一个来自Alan JT,他启发了我,lst是传递给defun的列表(第1项第2项第3项)
 
;; List Select Dialog (Temp DCL list box selection, based on provided list)
;; title - list box title
;; label - label for list box
;; height - height of box
;; width - width of box
;; multi - selection method ["true": multiple, "false": single]
;; lst - list of strings to place in list box
;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
(setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
(foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                  (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                  (strcat "width = " (vl-princ-to-string width) ";")
                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
            )
   (write-line x fo)
)
(close fo)
(new_dialog "list_select" (setq d (load_dialog fn)))
(start_list "lst")
(mapcar (function add_list) lst)
(end_list)
(setq item (set_tile "lst" "0"))
(action_tile "lst" "(setq item $value)")
(setq f (start_dialog))
(unload_dialog d)
(vl-file-delete fn)
(if (= f 1)
   ((lambda (s / i s l)
      (while (setq i (vl-string-search " " s))
      (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
      (setq s (substr s (+ 2 i)))
      )
      (reverse (cons (nth (atoi s) lst) l))
    )
   item
   )
)
)

rlx 发表于 2022-7-5 18:56:06

另一个重要来源是:http://web2.airmail.net/terrycad/Tutorials/MyDialogs.htm
 
 
在页面的一半左右,函数“my multilist”
 
 
玩得高兴

jonathann3891 发表于 2022-7-5 19:02:50

我想我可能被误解了。
 
这不使用DCL。
 
激活命令时,光标处会显示弹出菜单
 

 
正如你所见,我有菜单显示,它设置了变量。
 
如果选择pdf,我希望它运行以下操作:
 
(defun PDF(/)

(if (setq filename (getfiled "Specify Save Location" "" "pdf" 1))
(progn

(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ANSI expand D (34.00 x 22.00 Inches)" "I"
"L" "N" "E" "1:1" "C" "Y" "CMS_d_black.ctb" "Y" "N" "N" "N" filename "N" "Y")
)
)
(princ)
)

 
我的问题是我不知道谁该用cond。
 
像这样的??
 
(if psize
(cond
((= psize "11x17)
(defun PDF ()
blah
blah
blah

rlx 发表于 2022-7-5 19:08:49

您的代码是:
 
 



(cond
((= psize "11x17") (plot11x17))
((= psize "PDF")(plotPdF))
((= psize "22x34")(plot22x34))
(t (princ "\nPlot cancelled"))
)

 
 
gr.Rlx

jonathann3891 发表于 2022-7-5 19:13:15

谢谢你rlx!可以看出,我对编写lisp还是相当陌生的。
 
我以前从未使用过cond,所以我试图理解它的概念,它有点令人困惑。特别是当我不知道去哪里找信息的时候!
 
到目前为止我有这个
(defun c:test ()
(initget 1 "11x17 PDF 22x34");
(setq psize (getkword (strcat "\nSelect Plot :"))))
(cond
((= psize "11x17") (11x17))
((= psize "PDF")(PDF))
((= psize "22x34")(22x34))
(t (princ "\nPlot cancelled"))
)

 
现在,我如何合并pdf代码:
(defun PDF(/)

(if (setq filename (getfiled "Specify Save Location" "" "pdf" 1))
(progn

(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ANSI expand D (34.00 x 22.00 Inches)" "I"
"L" "N" "E" "1:1" "C" "Y" "CMS_d_black.ctb" "Y" "N" "N" "N" filename "N" "Y")
)
)
(princ)
)

Lee Mac 发表于 2022-7-5 19:14:41

大致如下:
(defun c:test ( / psize )
   (initget "11x17 PDF 22x34")
   (setq psize (getkword "\nSelect Plot <PDF>: "))
   (cond
       (   (= psize "11x17") (11x17))
       (   (= psize "22x34") (22x34))
       (   (pdf)   )
   )
   (princ)
)
(defun pdf ( / fnm )
   (if (setq fnm (getfiled "Specify Save Location" "" "pdf" 1))
       (progn
         (setvar 'tilemode 0)
         (command "-plot" "y" "" "Dwg To PDF.pc3" "ANSI expand D (34.00 x 22.00 Inches)" "I" "L" "N" "E" "1:1" "C" "Y" "CMS_d_black.ctb" "Y" "N" "N" "N" fnm "N" "Y")
       )
   )
)

BIGAL 发表于 2022-7-5 19:18:32

另一种方法是在P下面寻找情节
 

rlx 发表于 2022-7-5 19:26:40

 
别担心,我20年前就开始了,像李这样的人仍然让我觉得我是个初学者。但这可能是因为我唯一一个仍在运作的脑细胞开始显示出早衰的迹象;-)(这就是婚姻对男人的影响,可怕的哈哈)
页: [1] 2
查看完整版本: 带提示帮助的Lisp