请帮助使用hatch?
我想为我的同事自动化一个舱口,我想到了这个:(defun c:Test (/ hcol)
(prompt "1 = Gray | 2 = Blue | 3 = Green | 4 = Yellow | 5 = Red | 6 = Magenta")
(princ)
(setq hcol(getint "\nEnter COLOR:"))
(cond
((= hcol 1)(setq hcol (252)))
((= hcol 2)(setq hcol (2)))
((= hcol 3)(setq hcol (3)))
((= hcol 4)(setq hcol (5)))
((= hcol 5)(setq hcol (1)))
((= hcol 6)(setq hcol (200)))
)
(princ)
(command "_-hatch" pause "" "CO" hcol "")
(princ)
)
上面写着“错误:功能不好”
我的条件不对吗?? 删除括号。。。 (setq hcol (252))应为:
(setq hcol 252)
还有几个不必要的(princ)表达式-只有final(princ)才需要抑制最后一个计算表达式返回的值。
我还建议使用initget/getkword代替整数选项。
对非常感谢!
我会尽力做到的,
(defun c:Test (/ hcol)
(prompt "1 = Gray | 2 = Blue | 3 = Green | 4 = Yellow | 5 = Red | 6 = Magenta")
(setq hcol(getint "\nEnter COLOR:"))
(cond
((= hcol 1)(setq hcol 252))
((= hcol 2)(setq hcol 5))
((= hcol 3)(setq hcol 3))
((= hcol 4)(setq hcol 2))
((= hcol 5)(setq hcol 1))
((= hcol 6)(setq hcol 200))
)
(prompt "\npick point!") ; hot do i prompt the user to pick point on pause???
(command "_-hatch" "CO" hcolpause "")
(princ)
)
我做对了吗?对不起,如果我的代码很混乱,我开始学习这个lisp 我会更改提示,使其更便于用户使用:
您还可以让提示记住最后选择的,这样用户就可以在提示下按enter键。此外,您应该使用getpoint函数,而不是对图案填充部分使用暂停。
请注意,除非键入完整的单词,否则绿色关键字不会带有起始字符G Tharwat,我在发布之前没有检查我的代码,所以谢谢你指出这一点。修正后的代码为
(initget 1 "Grey Blue GReen Yellow Red Magenta")
(setq hcol (getkword "\nEnter COLOR : "))
非常感谢。这是一个好主意,而不是数字
但是我不知道你在说什么,我不知道该怎么合并它
由于灰色也具有相同的字符序列,因此前两个字符GR没有变化,也不会达到绿色。
玩一玩:
(defun c:HHatch(/ hcol clr)
(initget 1 "Gray Blue greeN Yellow Red Magenta")
(if (and (setq hcol (getkword "\nEnter COLOR : "))
(setq clr (nth (vl-position hcol '("Gray" "Blue" "greeN" "Yellow" "Red" "Magenta")) '(252 5 3 2 1 200)))
)
(command "_-hatch" "Properties" "_Solid" "_COLOR" clr "" pause "")
)
(princ)
)
Tharwat,我喜欢使用vl位置而不是条件位置,这看起来更好更干净。要使用getpoint,只需添加类似于9的东西,如果您希望用户能够像实际的图案填充循环那样继续拾取和图案填充,那么也可以使用while循环。
页:
[1]
2