明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1151|回复: 5

[讨论] 出错循环

[复制链接]
发表于 2013-5-8 12:33 | 显示全部楼层 |阅读模式
这个出错了两次就要重新执行命令,怎么设置成无限出错循环?
  1. (defun c:tt()
  2. (setvar "cmdecho"0)
  3.   (defun *error*(msg)
  4.       (setq txt(getint "\n加工数量<1>:"))
  5.   (if(= txt nil)
  6.     (setq txt 1))
  7.     (xh))

  8.   (setq txt(getint "\n加工数量<1>:"))
  9.   (if(= txt nil)
  10.     (setq txt 1))
  11.   (setq s(getreal "\n文字高度:"))
  12.   (if (= s nil)
  13.     (setq s 3.5)
  14.     )
  15.   (xh)
  16.   )

  17.   (defun xh()
  18.   (while txt
  19.     (setq pt(getpoint "\n文字位置:"))
  20.   (command "text" "j" "mc" pt s 0 (strcat "数量:" (itoa txt) "Pcs"))
  21.     )
  22.   )
  23.   
发表于 2013-5-8 16:52 | 显示全部楼层
你用捕获函数试试
Passes a list of arguments to a specified function and traps any exceptions

(vl-catch-all-apply 'function list)

Arguments

'function

A function. The function argument can be either a symbol identifying a defun, or a lambda expression.

list

A list containing arguments to be passed to the function.

发表于 2013-5-8 18:09 | 显示全部楼层
本帖最后由 仲文玉 于 2013-5-8 18:39 编辑

不知道你要什么效果,猜摸着改下,也不知道是不是这个意思?自己加下出错处理
  1. (defun c:ttt ()
  2.   (setvar "cmdecho" 0)
  3.   (setq txt (getint "\n加工数量<1>:"))
  4.   (if (= txt nil)(setq txt 1))
  5.   (setq s (getreal "\n文字高度:"))
  6.   (if (= s nil)(setq s 3.5))
  7.   (while (setq pt(getpoint "\n文字位置:"))
  8.     (command "text" "j" "mc" pt s 0 (strcat "数量:" (itoa txt) "Pcs"))
  9.     (setq  txt (1+ txt))
  10.   )
  11. )
 楼主| 发表于 2013-5-9 09:31 | 显示全部楼层
英雄无敌 发表于 2013-5-8 16:52
你用捕获函数试试
Passes a list of arguments to a specified function and traps any exceptions

怎么捕获?我想在插入文字那里右键可以重新输入加工数量.
 楼主| 发表于 2013-5-9 09:34 | 显示全部楼层
仲文玉 发表于 2013-5-8 18:09
不知道你要什么效果,猜摸着改下,也不知道是不是这个意思?自己加下出错处理

我想将这个程式改为循环插入加工件数,而且中途可以改加工数量,我加了出错处理目的是按了ESC键后程式跳到出错处理那里重新输入加工数量的,但是只可以运行两次之后就要重新执行命令了
发表于 2013-6-20 20:28 | 显示全部楼层
如果无限出错循环,那你还怎么退出啊?
lsp不是别的高级语言,可以有GOTO语句,如果你要点右键再回到输入数量,可以加一个while循环
(while (= 写好文字 nil)
(输入数量)
...
...
(if 写文字
(setq 写好文字 t)
(setq 写好文字 nil)


具体自己慢慢去体会,只是一个思路
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 23:43 , Processed in 0.492180 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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