明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3475|回复: 4

标准化输入对话框lisp代码

  [复制链接]
发表于 2008-4-19 09:12:00 | 显示全部楼层 |阅读模式
;;;标准输入对话框
;;;调用形式 (InputBox 显示的对话框名称 表( ( "editbox显示的说明" "editbox显示值" "editbox显示宽度") ...) )
;;;注意,调用参数均为字符串形式
;;;返回值为与输入表长度相等的字符串列表
;;;注意:以下代码未对输入代码格式进行检查,有需要时,需人加入格式检查的代码
(defun InputBox (strDialogName EditBoxDefList
/ ResultList fStream dclname tempFileName fileN fileStream templist i
dclid)
;;;-------------------------------------------------
(defun GetInput (len)
(setq i 1
ResultList nil
)

(repeat len
(setq ResultList
(append ResultList (list (get_tile (itoa i))))
)

(setq i (1+ i))
)
)
;;;-------------------------------------------------
(setq tempFileName (vl-filename-mktemp "dcltmp.dcl"))
(setq fileN (open tempFileName "w"))

(setq fileStream (list
"InputBox:dialog {\n"
(strcat "label =\"" strDialogName "\";\n")
)
)
(setq i 0)
(repeat (length EditBoxDefList)
(setq templist (nth i EditBoxDefList))
(setq fileStream (append fileStream
(list
":edit_box{\n"
"allow_accept = true ;\n"
(strcat "edit_width =" (caddr templist) ";\n")
"fixed_width = true ;\n"
(strcat "key =\"" (itoa (1+ i)) "\";\n")
(strcat "label=\"" (car templist) "\";\n")
(strcat "value=\"" (cadr templist) "\";\n")
)
)
)

(setq i (1+ i))
)

(setq fileStream (append fileStream
(list

"} ok_cancel;\n"
"}\n"
)
)
)
(foreach fStream
fileStream
(princ fStream fileN)
)
(close fileN)

(setq dclname tempFileName)


(setq dclid (load_dialog dclname))
(if (not (new_dialog "InputBox" dclid ""))
(progn (alert "对话框加载失败!") (exit))
)

(action_tile "accept" "(GetInput (length EditBoxDefList) ) (done_dialog 1)" )

(start_dialog)

(unload_dialog dclid)
(vl-file-delete dclname)

ResultList
)
;;;-------------------------------------------------
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2008-5-8 21:47:00 | 显示全部楼层
试试楼主的函数,谢谢分享!
发表于 2020-2-6 10:58:33 | 显示全部楼层
试试楼主的函数,谢谢分享!
发表于 2020-11-9 09:54:12 | 显示全部楼层
我试了一下,表里只有一项时是可以的,但表中有两项就出错了
发表于 2020-11-9 10:28:36 | 显示全部楼层
查到原因了,是少了一个括号
  1. ;;;标准输入对话框
  2. ;;;调用形式 (InputBox 显示的对话框名称 '( ( "editbox显示的说明" "editbox显示值" "editbox显示宽度") ...) )
  3. ;;;注意,调用参数均为字符串形式
  4. ;;;返回值为与输入表长度相等的字符串列表
  5. ;;;注意:以下代码未对输入代码格式进行检查,有需要时,需人加入格式检查的代码
  6. (defun InputBox  (strDialogName EditBoxDefList
  7.      /         ResultList    fStream
  8.      dclname       tempFileName  fileN
  9.      fileStream    templist       i
  10.      dclid n
  11.     )
  12. ;;;-------------------------------------------------
  13.   (defun GetInput (len / i)
  14.     (setq i 1
  15.     ResultList
  16.      nil
  17.     )

  18.     (repeat len
  19.       (setq ResultList
  20.        (append ResultList (list (get_tile (itoa i))))
  21.       )

  22.       (setq i (1+ i))
  23.     )
  24.   )
  25. ;;;-------------------------------------------------
  26.   (setq tempFileName (vl-filename-mktemp "dcltmp.dcl"))
  27.   (setq fileN (open tempFileName "w"))

  28.   (setq  fileStream
  29.    (list
  30.      "InputBox:dialog {\n"
  31.      (strcat "label =\"" strDialogName "\";\n")
  32.    )
  33.   )
  34.   (setq i 0)
  35.   (repeat (length EditBoxDefList)
  36.     (setq templist (nth i EditBoxDefList))
  37.     (setq fileStream
  38.      (append fileStream
  39.        (list
  40.          ":edit_box{\n"
  41.          "allow_accept = true ;\n"
  42.          (strcat "edit_width =" (caddr templist) ";\n")
  43.          "fixed_width = true ;\n"
  44.          (strcat "key =\"" (itoa (1+ i)) "\";\n")
  45.          (strcat "label=\"" (car templist) "\";\n")
  46.          (strcat "value=\"" (cadr templist) "\";\n")
  47.          "}"
  48.        )
  49.      )
  50.     )

  51.     (setq i (1+ i))
  52.   )

  53.   (setq  fileStream
  54.    (append fileStream
  55.      (list

  56.        "ok_cancel;\n"
  57.        "}\n"
  58.      )
  59.    )
  60.   )
  61.   (foreach n
  62.        fileStream
  63.     (princ n fileN)
  64.   )
  65.   (close fileN)

  66.   (setq dclname tempFileName)


  67.   (setq dclid (load_dialog dclname))
  68.   (if (not (new_dialog "InputBox" dclid ""))
  69.     (progn (alert "对话框加载失败!") (exit))
  70.   )

  71.   (action_tile
  72.     "accept"
  73.     "(GetInput (length EditBoxDefList) ) (done_dialog 1)"
  74.   )

  75.   (start_dialog)

  76.   (unload_dialog dclid)
  77.   (vl-file-delete dclname)

  78.   ResultList
  79. )
  80. ;;;-------------------------------------------------


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-17 14:33 , Processed in 0.223948 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表