Lee Mac 发表于 2022-7-5 17:28:06

FWIW,这是另一个版本,允许用户以任何顺序拾取矩形角点,并考虑任何UCS(假设UCS轴平行于矩形):

(defun c:rprof ( / fn1 fn2 pt1 pt2 rgt thk tmp top )
   (if (and (setq pt1 (getpoint "\nSpecify first corner: "))
            (setq pt2 ((if (zerop (getvar 'worlducs)) getpoint getcorner) pt1 "\nSpecify opposite corner: "))
       )
       (progn
         (setq thk (cond ((getdist "\nSpecify thickness <25.4>: ")) (25.4))
               fn1 (lambda ( x ) (mapcar '+ x (list 0 thk 0)))
               fn2 (lambda ( x ) (mapcar '+ x (list thk 0 0)))
               tmp (mapcar 'max pt1 pt2)
               pt1 (mapcar 'min pt1 pt2)
               pt2 tmp
               top (mapcar 'fn1 (list (cons (car pt1) (cdr pt2)) pt2))
               rgt (mapcar 'fn2 (list (cons (car pt2) (cdr pt1)) pt2))
         )
         (myrectangle (append top (reverse (mapcar 'fn1 top))))
         (myrectangle (append rgt (reverse (mapcar 'fn2 rgt))))
       )
   )
   (princ)
)
(defun myrectangle ( lst )
   (   (lambda ( ocs )
         (entmake
               (append
                  '(   (000 . "LWPOLYLINE")
                     (100 . "AcDbEntity")
                     (100 . "AcDbPolyline")
                     (090 . 4)
                     (070 . 1)
                   )
                   (list (cons 038 (caddr (trans (car lst) 1 ocs))))
                   (mapcar '(lambda ( x ) (cons 10 (trans x 1 ocs))) lst)
                   (list (cons 210 ocs))
               )
         )
       )
       (trans '(0 0 1) 1 0 t)
   )
)
(princ)

 

Grrr 发表于 2022-7-5 17:30:06

 
谢谢李!
我实际上测试了性能,通过将代码粘贴到控制台,没有收到这个错误,实际上没有错误,也没有VLIDE提示/中断,当我使用:
但是当我提供一个参数时:
控制台确实因错误而中断(我的“出错时中断”选项始终处于选中状态)。
关于mapcar。。我开始经常练习列表操作。(唯一的缺点是,我们大多数编写代码的人都不是Matematician,这可能会揭示几何任务的更多潜力(显然不适用于你!)。
 
这是更好的方式,这是一件好事,你保持形状的练习!
 
主题外:
我有一些(对我来说很有趣)的问题,希望你不介意回答(如果/当你有空的时候)。

Lee Mac 发表于 2022-7-5 17:35:07

 
如果您完全按照帖子中所示计算表达式,那么实际上,您不会收到第一个表达式的错误,因为这只会返回一个指向*error*符号的函数定义的指针,以及nil。然而,第二个表达式将返回指针,然后尝试将符号“m”作为函数求值(如果未定义“m”,则显然会出错)。
 
然而,这两个测试都没有评估*错误*功能-请观察以下内容:
Command: (defun foo ( / *error* ) (defun *error* nil (princ)) (/ 1 0))
FOO
Command: (foo)
too many arguments
Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ m) (princ)) (/ 1 0))
FOO
Command: (foo)
divide by zero
 
谢谢-我希望我能为论坛做出贡献,同样地,更经常地更新我的网站,但不幸的是,我没有那么多的空闲时间参加。

Grrr 发表于 2022-7-5 17:36:54

Lee,实际上在第二个代码中,*error*确实进行了计算(它打印了m符号),请参阅添加自定义提示消息:
 

Command: (defun foo ( / *error* ) (defun *error* nil (princ "\nError is evaluated.")(princ)) (/ 1 0))
FOO
Command: (foo)
too many arguments

 

Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 0))
FOO
Command: (foo)
Error is evaluated.divide by zero

 
强制*error*进行评估(就像您在动态使用对话框时所做的那样):

Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 1) (*error* nil))
FOO
Command: (foo)
Error is evaluated.nil

 
无错误,无*错误*评估:

Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 1))
FOO
Command: (foo)
1

 
当你不在的时候,这很明显,但有一些工作是一件好事,对吗?

Lee Mac 发表于 2022-7-5 17:41:36

 
从您的帖子中,我了解到您正在键入表达式:
直接在VLIDE控制台-因此我之前的澄清。
 
但为了完整性:*error*函数定义始终需要单个字符串值参数(错误消息),当遇到错误时,解释器会自动提供该参数。

Grrr 发表于 2022-7-5 17:44:29

不,不,事实上,当没有提供参数时,(m)不会评估*错误*,并且当出现错误时,VLIDE可能会保持沉默,抱歉误解。
 
即。:

_$ (defun foo ( / *error* ) (defun *error* nil (princ "\nError is evaluated.")(princ)) (/ 1 0))
FOO
_$ (foo)
_$ (foo)
_$ (foo)
_$ (defun foo ( / *error* ) (defun *error* (m) (princ "\nError is evaluated.")(princ)) (/ 1 0))
FOO
_$ (foo)

Error is evaluated.
_1$ (foo)
_$ (foo)

Error is evaluated.
_1$

Lee Mac 发表于 2022-7-5 17:48:54

 
我认为有一些困惑-
 
通过将*error*函数定义为:
不是在求值过程中没有为函数提供参数,而是函数不能用参数求值。
 
您不会在Visual LISP IDE中收到错误,因为无法评估错误处理程序:您通过定义局部*error*函数重新定义了内置错误处理程序,但无法评估该局部*error*函数,因此错误无处可去。
 
实际上,令我惊讶的是,命令行历史记录甚至报告了“太多的参数”,但这不是来自内置错误处理程序,因为消息的前缀不是典型的“error:”。

Grrr 发表于 2022-7-5 17:51:42

听起来很有趣,关于发现vl的“一网打尽”应用行为。
 
 
无论何时在VLIDE控制台中运行此函数,与在命令提示符下运行此函数,都可能会略有不同:
15
16
看起来命令提示符试图将错误消息传递给*error*函数,这就是为什么我得到了太多参数错误,类似于此:
17
页: 1 [2]
查看完整版本: 顶视图和侧视图矩形