代码改变世界

AutoLISP绘制花型三

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

AutoLISP绘制花型三,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq en1 (car (entsel "\n选取圆1:")))
  (setq en2 (car (entsel "\n选取圆2:")))
  (setq en1data (entget en1))
  (setq en2data (entget en2))
  (setq cen1 (cdr (assoc 10 en1data)))
  (setq cen2 (cdr (assoc 10 en2data)))
  (setq r1 (cdr (assoc 40 en1data)))
  (setq r2 (cdr (assoc 40 en2data)))
  (setq ang (angle cen1 cen2))
  (setq p1 (polar cen1 (+ ang (/ pi 2)) r1))
  (setq p2 (polar cen1 (- ang (/ pi 2)) r1))
  (setq p3 (polar cen2 (+ ang (/ pi 2)) r2))
  (setq p4 (polar cen2 (- ang (/ pi 2)) r2))
  (command "line" "tan" p1 "tan" p4 "")
  (setq en3 (entlast))
  (command "line" "tan" p2 "tan" p3 "")
  (setq en4 (entlast))
  (setq nn (getint "\n重复次数<8>:"))
  (if (null nn) (setq nn 8))
  (command "trim" en3 en4 "" (list en2 (polar cen2 ang (* -1 r2))) "")
  (command "array" en3 en4 (polar cen2 ang r2) "" "p" cen1 nn "" "")
  (prin1)
  )

代码完。