使用上一个输入
(defun c:xLucky(/ hcol) (command "select" pause)(setq hcol (getint "\nEnter Number: "))
(command "chprop" "p" "" "c" hcol ""))
如何将我输入的前一个数字设置为“hcol”的值,这样我就不会反复键入该值,除非我键入不同的值并再次使用它。。 这样地?
(defun c:xLucky( / )
(command "_.select" pause)
(or *hcol* (setq *hcol* 1))
(or (setq *hcol* (getint (strcat "\nEnter Number: <" (itoa *hcol*) ">: "))) *hcol*)
(command "_.chprop" "p" "" "c" *hcol* "")
(princ)
)
请注意,*hcol*现在是一个全局变量,不应包括在参数列表中。
小心-如果用户在提示下按enter键,则会将*hcol*设置为零。
正确,刚刚测试过-比我想象的要难,所以我找到了两个解决方案:
1.使用“使用默认选项提示”教程中的最后一个示例http://www.lee-mac.com/promptwithdefault.html(一定很喜欢)
(defun c:test ( / )
(command "_.select" pause)
(or (numberp *hcol*) (setq *hcol* 1))
(setq *hcol* (cond ( (getint (strcat "\nChoose a Number <" (itoa (setq *hcol* (cond ( *hcol* ) ( 1 )))) ">: " ))) ( *hcol* )))
(command "_.chprop" "p" "" "c" *hcol* "")
(princ)
)
2.使用我上周想到的一些伪函数:
(defun c:test ( / )
(command "_.select" pause)
(or (numberp *hcol*) (setq *hcol* 1))
(setq *hcol* (_or (list (getint (strcat "\nEnter Number: <" (itoa *hcol*) ">: ")) *hcol*)))
(command "_.chprop" "p" "" "c" *hcol* "")
(princ)
)
; (_or (list (getpoint "\nFirst try: ") (getpoint "\nSecond try: ") (getpoint "\nThird try: ") ))
(defun _or ( LstOfAnythings / r ); return the first non-nil value, instead of just T or nil, seems to work
(vl-some
(function
(lambda (x)
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'eval (list 'x))))
(setq r x)
)
)
)
LstOfAnythings
)
r
)
顺便说一句,在测试代码之后,对于最近线程上的另一个请求,在cadtutor上的结果性能似乎相似。
我不确定cond到底是如何工作的,我测试了and/or/if函数,但没有成功。
我认为cond将评估您提供的尽可能多的测试语句,如果所有内容都评估为nil(或者测试语句完全不相关),它将运行最后一个语句(T)。
我“使用/知道”它,因为我在这个论坛上,每次我觉得奇怪/不确定,而使用它。必须用它做更多的实验。 @Grrr:您上一篇文章的第一个代码示例包含多余的一行。。。
请小心,因为此表达式不会按预期进行计算:在构造返回值列表并将其传递给您的“_or”函数之前,将对所有getpoint表达式进行计算(无论之前的响应如何)。
这种行为不同于AutoLISP或函数的行为,AutoLISP或函数是一种特殊形式,这意味着对每个连续参数的求值取决于对具有先前参数的函数的求值。为了复制这种行为,getpoint表达式的列表应作为未赋值(文字)列表传递,表达式在vl some表达式中求值。 另一个
检查hcol是否为零将hcol设置为起始值
如果hcol/=nil,则提示具有当前值
按接受当前值或输入新值。
; found this
(if (= vert nil)(setq vert 50)) ; sets an initial value for message
(prompt "\nEnter Vertical scale:<")
(prin1 vert)
(prompt ">:")
(setq newvert (getint))
(if (= newvert nil)
(princ); use current vert value
(setq vert newvert) ; set vert to new value
)
是的,我知道它会计算所有的getpoint表达式,无法解决这个问题,直到遵循您的建议,传递未计算参数的列表:
(defun _or ( LstOfAnythings / r ); return the first non-nil value, instead of just T or nil, seems to work
(apply 'and (mapcar '(lambda (x) (= 'STR (type x))) LstOfAnythings))
(vl-some
(function
(lambda (x)
(and
(not (vl-catch-all-error-p (setq r (vl-catch-all-apply 'eval (list (read x))))))
(not (eq r nil))
)
)
)
LstOfAnythings
)
r
)
测试功能:
(if ; test function
(setq p
(_or
(list
"(getpoint \"\nFirst try: \")"
"(getpoint \"\nSecond try: \")"
"(getpoint \"\nThird try: \")"
)
)
)
(entmakex (list (cons 0 "POINT") (cons 62 1) (cons 10 p)))
)
谢谢
我觉得可能还有另一种方式来申请。
对不起,罗伊,我什么都看不见。。有什么提示吗?
引用文字表达式也就足够了,例如:
(defun _or ( lst )
(vl-some '(lambda ( x / r ) (if (not (vl-catch-all-error-p (setq r (vl-catch-all-apply 'eval (list x))))) r)) lst)
)
(if (setq p (_or '((getpoint "\n1st try: ") (getpoint "\n2nd try: ") (getpoint "\n3rd try: "))))
(entmakex (list (cons 0 "POINT") (cons 62 1) (cons 10 p)))
) 假设*hcol*为零或整数,则不需要此行:
下一行已经处理好了:
(itoa (setq *hcol* (cond ( *hcol* ) ( 1 ))))
页:
[1]
2