AutoLISP for 摩天轮绘图仅绘制主圆

问题描述 投票:0回答:1

我有这段代码可以用 AutoLISP 绘制摩天轮,但我似乎不明白为什么它不起作用。

(defun c:ferriswheel ()
  (setq radius 50)
  (setq cart-size 5)
  (setq num-carts 8)

  (setq center-point '(0 0 ))

  (command "circle" center-point radius)

  (setq angle (/ (* 2 pi) num-carts))
  (setq current-angle 0)

  (repeat num-carts
    (setq x1 (* radius (cos current-angle)))
    (setq y1 (* radius (sin current-angle)))

    (setq x2 (* (+ radius cart-size) (cos current-angle)))
    (setq y2 (* (+ radius cart-size) (sin current-angle)))

    (command "line" (list x1 y1) (list x2 y2))
    (setq current-angle (+ current-angle angle))

   )
)

它不仅只画圆圈,而不画手推车,而且还向我展示了一个窗口,上面写着

分配给受保护的符号:
角度
进入中断循环?
是/否

网上查了一下,他们说忽略它,直接点击“否”,这会导致代码自行取消,只留下绘制的圆圈。请帮忙!

lisp autocad autolisp
1个回答
0
投票

这是因为命令

LINE
在第二点之后没有结束。它要求下一个点继续绘制。 您应该在 ""
 末尾使用 
(command "line" (list x1 y1) (list x2 y2) )

来结束绘制

所以你应该这样使用它:

(command "line" (list x1 y1) (list x2 y2) "" )

顺便说一句:调用函数名称变量

angle
是个坏主意。如果您尝试使用
angle
作为函数,您将得到
ERROR: undefined function

© www.soinside.com 2019 - 2024. All rights reserved.