乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 89|回复: 6

[编程交流] 使用DCL验证用户Inp

[复制链接]

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-5 22:51:53 | 显示全部楼层 |阅读模式
我正在使用一个相当简单的DCL应用程序,它是从Jeffery P.Sanders网站教程中获得的:
  1. (defun GetUserInput ()
  2. (setq server_path "//a_very_long_novell_path/")
  3. ;;;--- Try to load the DCL file from disk into memory
  4. (if(not(setq dcl_id (load_dialog (strcat server_path "MyDCLFile.dcl"))))
  5.    (progn
  6.      (alert "The DCL file could not be loaded.")
  7.      (exit)
  8.    )
  9.    ;;;--- Else, the DCL file was loaded into memory
  10.    (progn
  11.      ;;;--- Try to load the definition inside the DCL file
  12.      (if (not (new_dialog "MyDCL" dcl_id))
  13.        (progn
  14.          (alert "The definition could not be found inside the DCL file")
  15.          (exit)
  16.        )
  17.        ;;;--- Else, the definition was loaded, we are ready to roll
  18.        (progn
  19.          ;;;--- If an action event occurs, do this function
  20.          (action_tile "cancel" "(done_dialog 1)")
  21.          (action_tile "accept" "(saveVars)(done_dialog 2)")
  22.          ;;;--- Display the dialog box
  23.          (setq ddiag(start_dialog))
  24.          ;;;--- If the cancel button was pressed - display message
  25.          (if (= ddiag 1)
  26.            (princ "\n \n ...EXAMPLE Cancelled. \n ")
  27.          )
  28.          ;;;--- If the "Okay" button was pressed
  29.          (if (= ddiag 2)
  30.            (princ "\n \n ...Example Complete!")
  31.          )  
  32.        )
  33.      )
  34.    )
  35. )
  36. ;;;--- Suppress the last echo for a clean exit
  37. (princ)
  38. ); end GetUserInput function
  39. (defun Popup ( title msg flags / wsh )
  40. (vl-catch-all-apply
  41.    (function
  42.      (lambda nil
  43. (setq wsh (vlax-create-object "WScript.Shell"))
  44. (setq res (vlax-invoke-method wsh 'popup msg 0 title flags))
  45. )
  46.      )
  47.    )
  48. (if wsh (vlax-release-object wsh))
  49. res
  50. )

我想做的是在退出此例程之前验证用户的输入。它需要两个输入,一个跨度和一个宽度。我正在检查它们是否在有限范围内,然后它进入程序的另一部分。但是如果用户输入了无效的内容,我想警告他们。。。我用李·Mac的弹出程序来做这件事,但一旦他们在收到错误警告后按OK,我希望程序DCL重置并再次询问用户,并不断询问用户输入,直到他们得到正确的结果。有谁能就如何最好地处理这个问题提出一些建议吗?
 
我让它工作并检查有效输入,但现在它只是退出。我正在寻找一种方法,以不断重复输入,直到用户得到它的权利。
 
再次证明,这很难,但确实能够编写复杂的代码来进行计算和绘制图形。最困难的部分是防止用户扔进垃圾桶,如果他们出错,再给他们一次机会。
回复

使用道具 举报

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 23:02:01 | 显示全部楼层
当一个对话框被丢弃(done\u dialog)时,lisp将继续运行,并将用户输入的值保存在变量中(在您的示例中,它是由(saveVars)函数完成的)。
你可以用两种方法。
-检索并验证这两个值。根据哪一个无效(或两者都无效),您可以创建警告弹出窗口,然后再次启动GetUserInput。如果1个输入在可接受的范围内,则最好在重新启动dcl时将其放回原位。这样,如果你在其中一个页面上输入了错别字,你就不必同时输入这两个页面。需要记住的一点是:如果您获得无效输入并第二次启动,当第二个实例的完成将完成时,代码将“返回”到第一次执行中,以处理取消“重新启动”后的所有内容。(类似递归函数)。很好的解决方法(我认为):(if[无效](prong(getuserinput)(exit)))。
-更好的是(我会这样做),在dcl中添加一个空文本区域,以提供反馈,告诉用户为什么输入无效。您可以更改accept按钮的执行并添加if语句。如果值超出范围,根据输入错误及其原因,仅使用适当的注释更新文本区域。即“跨度值不能超过x英寸”。如果在可接受的范围内,则继续“(saveVars)(完成对话框2)”。这样,不会丢弃无效输入,但您不需要“重复”任何内容。您还可以更改焦点,将其放回故障字段。这很容易做到,也很漂亮。
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 23:18:39 | 显示全部楼层
你好
 
尝试这个简单的示例,它展示了使用错误平铺属性的一种方法,它应该非常清楚地演示示例的目的。
 
DCL代码(保存到test.DCL)
 
  1. test : dialog
  2.        { label = "Example";
  3.            : boxed_row {
  4.            : edit_box { label = "First  : "; key = "f"; alignment = right; width = 16; fixed_width = true;}
  5.            : edit_box { label = "Second :";  key = "s"; alignment = right; width = 20; fixed_width = true;}
  6.            
  7.        }
  8.        : spacer { height = 0.5;}
  9.        : boxed_row { alignment = centered;
  10.        : button { label = "accept"; key = "ok"; is_default = true; }
  11.        : button { label = "cancel"; key = "esc"; is_cancel = true; }
  12.        }
  13.        : errtile { key = "a"; alignment = centered;}
  14.        : errtile { key = "b"; alignment = centered;}
  15.        }

 
lisp代码。
 
  1. (defun c:test (/ NumbersOnly dcl_id)
  2. ;;    Tharwat 21.6.2014        ;;
  3. (defun NumbersOnly (/ l)
  4.    (mapcar 'set_tile '("a" "b") '("" ""))
  5.    (setq l (mapcar 'get_tile '("f" "s")))
  6.    (cond ((and (not (numberp (read (car l))))
  7.                (not (numberp (read (cadr l))))
  8.           )
  9.           (mapcar 'set_tile
  10.                   '("a" "b")
  11.                   (list "Only numbers is allowed in First cell"
  12.                         "Only numbers is allowed in Second cell"
  13.                   )
  14.           )
  15.          )
  16.          ((not (numberp (read (car l))))
  17.           (set_tile "a" "Only numbers is allowed in First cell")
  18.          )
  19.          ((not (numberp (read (cadr l))))
  20.           (set_tile "b" "Only numbers is allowed in Second cell")
  21.          )
  22.          (t
  23.           (done_dialog)
  24.          )
  25.    )
  26. )
  27. (setq dcl_id (load_dialog "test.dcl"))
  28. (if (not (new_dialog "test" dcl_id))
  29.    (progn (alert " Error in loading the dialog (test.dcl) ")
  30.           (exit)
  31.    )
  32. )
  33. (action_tile "ok" "(NumbersOnly)")
  34. (action_tile "esc" "(done_dialog)")
  35. (start_dialog)
  36. (unload_dialog dcl_id)
  37. (princ)
  38. )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 23:28:00 | 显示全部楼层
比尔,你想过一个滑动条,然后你不能超过最大值。您可以在调用它之前设置最小-最大inc。
 
  1. : slider {
  2.                    key = "size2";
  3.                    min_value  = 1;
  4.                    max_value = 250;
  5.                    value = 110;
  6.                    big_increment = 5;
  7.                    }
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-5 23:37:08 | 显示全部楼层
嘿,这看起来很酷。我今天应该试试。。。但是现在,会议,会议,会议。我认为我们应该召开一次关于所有会议的会议。
回复

使用道具 举报

180

主题

639

帖子

463

银币

中流砥柱

Rank: 25

铜币
897
发表于 2022-7-5 23:49:39 | 显示全部楼层
再次感谢大家对我正在开发的DCL应用程序的帮助。我想知道是否有人能在这方面给我更详细的帮助。以下是我目前掌握的情况:
 
我写了一个脚本,可以从自定义菜单项启动。该脚本加载包含所需块的图形文件,然后加载并执行LISP文件。在此LISP文件中,DCL的以下功能再次由Jeffery P.Sander的网站提供:
 
  1. (defun GetUserInput ()
  2. (setq server_path "//a_very_long_novell/path/")
  3. ;;;--- Try to load the DCL file from disk into memory
  4. (if(not(setq dcl_id (load_dialog (strcat server_path "MyDCLFile.dcl"))))
  5.    (progn
  6.      (alert "The DCL file could not be loaded.")
  7.      (exit)
  8.    )
  9.    ;;;--- Else, the DCL file was loaded into memory
  10.    (progn
  11.      ;;;--- Try to load the definition inside the DCL file
  12.      (if (not (new_dialog "SingleGrt" dcl_id))
  13.        (progn
  14.          (alert "The definition could not be found inside the DCL file")
  15.          (exit)
  16.        )
  17.        ;;;--- Else, the definition was loaded, we are ready to roll
  18.        (progn
  19.          ;;;--- If an action event occurs, do this function
  20.          (action_tile "cancel" "(done_dialog 1)")
  21.          (action_tile "accept" "(saveVars)(done_dialog 2)")
  22.          ;;;--- Display the dialog box
  23.          (setq ddiag(start_dialog))
  24.          ;;;--- If the cancel button was pressed - display message
  25.          (if (= ddiag 1)
  26.            (princ "\n \n ...EXAMPLE Cancelled. \n ")
  27.          )
  28.          ;;;--- If the "Okay" button was pressed
  29.          (if (= ddiag 2)
  30.            (princ "\n \n ...Example Complete!")
  31.          )  
  32.        )
  33.      )
  34.    )
  35. )
  36. ;;;--- Suppress the last echo for a clean exit
  37. (princ)
  38. ); end GetUserInput function
  39. (defun saveVars()
  40. ;;;--- Save the input from the dialog box
  41. (setq dwgno (get_tile "dwgno")
  42. Span (atof (get_tile "dimA"))
  43. Width (atof (get_tile "dimB"))
  44. )
  45. )
  46. (defun Popup ( title msg flags / wsh )
  47. (vl-catch-all-apply
  48.    (function
  49.      (lambda nil
  50. (setq wsh (vlax-create-object "WScript.Shell"))
  51. (setq res (vlax-invoke-method wsh 'popup msg 0 title flags))
  52. )
  53.      )
  54.    )
  55. (if wsh (vlax-release-object wsh))
  56. ;res
  57. )

这是dcl文件:
  1. SingleGrt : dialog {
  2.          label = "My DCL Window";
  3.          initial_focus = "dwgno";
  4.          : column {
  5.            : row {
  6.              : boxed_column {
  7.                : edit_box {
  8.                  key = "dwgno";
  9.                  label = "Drawing Number";
  10.                  edit_width = 12;
  11.                  value = "";
  12.                }
  13.              }
  14.            }
  15.     : row {
  16.         : edit_box {
  17.           key = "dimA";
  18.           label = "A Dim (Span)";
  19.           edit_width = 10;
  20.                  value = "";
  21.                }
  22.            }
  23.     : row {
  24.         : edit_box {
  25.           key = "dimB";
  26.           label = "B Dim (Width)";
  27.           edit_width = 10;
  28.                  value = "";
  29.                }
  30.            }
  31.            : row {
  32.              : boxed_row {
  33.                : button {
  34.                  key = "accept";
  35.                  label = " Okay ";
  36.                  is_default = true;
  37.                }
  38.                : button {
  39.                  key = "cancel";
  40.                  label = " Cancel ";
  41.                  is_default = false;
  42.                  is_cancel = true;
  43.                }
  44.              }
  45.            }
  46.          }
  47. }

这是可行的,但我更喜欢塔瓦的方法。说实话,我只是没有足够的DCL经验来理解他做了什么。
DCL需要请求四种不同的输入:
dwgno公司
跨度
宽度
格栅顶部
dwgno可以是任何数字字符串、数字、字母,但不能是#%@等特殊字符。。。
跨度将限制在12“和60”之间
宽度将限制在12“和193”之间
光栅顶部将是任何十进制数,但不应大得离谱。我认为将其限制在1“到24”之间就足够了。
如果用户输入了任何无效的内容,我想快速警告他们,然后让他们重新开始,而不删除他们已经输入的内容。只需给他们一个机会,将错误字段更改为有效答案。它需要一直这样做,直到所有四个字段都被正确填写。
完成后,剩下的代码将接受这四个变量,并发挥神奇的作用。
 
顺便说一句,这将自动创建铝格栅板的制造细节表。我已经很好地完成了代码的编写,但这最后一块拼图将充分证明用户只能输入有效数据,我只需要完成它。如有任何帮助,我们将不胜感激。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 00:01:05 | 显示全部楼层
如果您使用滑块,您可以链接编辑框,使其显示当前值。不确定您是否可以将其锁定为无输入。我使用它的示例允许用户滑动或输入。
 
您有旧版Autocad Customization Guide mine is Release 12(非2012)的副本吗?Autocad帮助中有每种方法的示例
 
好的,它使用文本输出来显示值,看看底部的总宽度。
 
235158pxcal7k686if6ran.jpg
 
  1. : boxed_column {
  2.                    : row {
  3.                    label = "Total width";                 
  4.                    : text {
  5.                    key = "cav7";
  6.                    width = 3;
  7.                    fixed_width = true;
  8.                    value = "270";
  9.                }
  10.            }
  11.            }      
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-11 03:33 , Processed in 0.584050 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表