代码改变世界

AutoLISP 绘制滚轮

2011-03-28 08:57  精诚所至 金石为开  阅读(307)  评论(0编辑  收藏  举报

AutoLISP 自动绘制滚轮,代码如下。

(defun c:test()
  (setq cen1 (getpoint "\n中心点:"))
  (setq rr1 (getdist cen1 "\n大圆半径:"))
  (command "circle" cen1 rr1)
  (setq en1 (entlast))
  (command "circle" cen1 "d" rr1)
  (setq cen2 (polar cen1 0 rr1))
  (setq rr2 (getdist cen2 "\n小圆半径:"))
  (setq nn (getint "\n重复次数<8>:"))
  (if (null nn) (setq nn 8))
  (setq ang 0 ss (ssadd))
  (setq angdd (/ (* pi 2) nn))
  (repeat nn
    (command "circle" cen2 rr2)
    (setq ss (ssadd (entlast) ss))
    (setq ang (+ ang angdd))
    (setq cen2 (polar cen1 ang rr1))
    )
  (setq ang 0)
  (repeat nn
    (command "trim" ss "" (polar cen1 ang rr1) "")
    (setq ang (+ ang angdd))
    )
  (setq ang1 (* -1 (/ angdd 2.0)) ang2 (+ ang1 angdd) ang 0)
  (repeat nn
    (command "trim" (polar cen1 ang1 rr1) (polar cen1 ang2 rr1) "" (polar cen1 ang (- rr1 rr2)) "")
    (setq ang1 (+ ang1 angdd) ang2 (+ ang2 angdd) ang (+ ang angdd))
    )
  (prin1)
  )

代码完。