我很高兴能帮上忙。
关于最后发布的代码的一点评论。。。while语句只有在所包含的下一个表达式不是nil时才会继续。
如果你有
- (while (setq hsel (car (entsel "\nSelect hatch: ")))
...这意味着,如果您误点击(和/或选择nothing),hsel将为零,并且while语句此时停止计算。这也意味着,事实上,您的第一个conditional(=hsel nil)没有用处,永远无法满足/执行。有时我使用一些标志变量作为while标准(有时与“and或”或“or”组合到任何其他标准以满足我的需要),对于每个可能的结果,我使用/更改标志来控制while。非常基本的示例
- (defun c:hatchangle (/ hsel pt1 pt2 angr angd whilestop keepgoingflag *error*)
- (defun *error* (msg)
- (if (not
- (member msg '("Function cancelled" "quit / exit abort"))
- )
- (princ (strcat "\nError: " msg))
- )
- )
- [color="darkorange"](setq keepgoingflag T)[/color]
- (while [color="darkorange"](or[/color] (setq hsel (car (entsel "\nSelect hatch: "))); [b]with a "or" if you misclick and select nothing...[/b]
- [color="darkorange"]keepgoingflag)[/color]; [b]...the flag will prevent the while statement to stop being evaluated[/b]
- (cond
- ((= hsel nil);[b]now this cond can be evaluated[/b]
- (princ "\nNothing selected. Try again or hit escape to end command"); [b]and now escape is the only way out[/b]
- )
- ((= "HATCH" (cdr (assoc 0 (entget hsel))))
- (if (and (setq pt1 (getpoint "\nSelect 1st point for reference angle: "))
- (setq pt2 (getpoint "\nSelect 2nd point for reference angle: "))
- )
- (progn
- (setq angr (angle pt1 pt2))
- (setq angd (/ (* angr 180) pi))
- (command "._-hatchedit" hsel "" "" "" angd)
- (princ)
- )
- )
- )
- (t
- (princ "\nNot a hatch, try again.")
- )
- )
- )
- (princ)
- )
有时候,简单的一段时间就足够了,有时候你需要绕着它转一圈。
快乐的编码!
杰夫! |