代码改变世界

AutoCADLISP绘制楼梯

2011-03-27 22:52  精诚所至 金石为开  阅读(442)  评论(0编辑  收藏  举报

AutoCAD LISP绘制楼梯,控制方向和阶数高度等,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq nn (getint "\n阶数<5>:"))
  (if (null nn) (setq nn 5))
  (setq pt1 (getpoint "\n第一点:"))
  (setq pt2 (getpoint "\n第二点:"))
  (setq ww (distance pt1 pt2))
  (setq str_hh (strcat "\n高度<" (rtos ww 2) ">:"))
  (setq hh (getdist pt1 str_hh))
  (if (null hh) (setq hh ww))
  (setq ang (angle pt1 pt2))
  (setq ptbas pt2)
  (command "pline" pt1 ptbas)
  (repeat nn
    (setq ptbas (polar ptbas (+ ang (/ pi 2)) (/ hh nn)))
    (command ptbas)
    (setq ptbas (polar ptbas (+ ang pi) (/ ww nn)))
    (command ptbas)
    )
  (command "c")
  (prin1)
  )

代码完。