好主意pBe
使用vl,您可以将其缩短为:
- (defun c:Test ( / _errormsg a b c d )
- (defun _errormsg ( lst / x )
- (if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst))
- (alert x)
- )
- )
- (cond
- (
- (and
- (setq a (car (entsel "\nSelect Line:")))
- (setq b (eq (cdr (assoc 0 (entget a))) "LINE"))
- (setq c (getint "\nEnter Number of Cars: "))
- (setq d (getpoint "\nPick Point on screen: "))
- (princ "\nDone All Three:")
- )
- )
- ( t
- (_errormsg
- '(
- (a "Failed to select Object")
- (b "Not a Line Entity")
- (c "Failed to Enter Number")
- (d "Failed to pick a point")
- )
- )
- )
- )
- (princ)
- )
可以使用以下表达式:
其中是一个函数,当提供null点参数时会出错。
然而,在我看来,我觉得这是一种糟糕的编程实践,因为你在等待某些东西失败,而不是从一开始就防止错误。
由于vl catch all apply函数采用与apply函数相同的参数,因此每次都会出错。使用上述代码,您将所选点(或nil)作为参数列表传递,这相当于:
- (apply 'cadr '(1 2 3)) == (cadr 1 2 3)
这将出错。
但是,请注意,cadr函数不需要vl catch all apply构造,因为
|