AutoCAD LISP利用子程序绘制田字格,代码如下。
(defun c:pbox()
(get_pbox_data)
(draw_pbox)
(prin1)
)
(defun get_pbox_data()
(setq pa (getpoint "请输入左下角点:"))
(setq ww (getdist pa "\n宽度:"))
(setq hh (getdist pa "\n高度:"))
)
(defun draw_pbox()
(setq pb (polar pa 0 ww))
(setq pc (polar pb (/ pi 2) hh))
(setq pd (polar pc pi ww))
(command "pline" pa pb pc pd "c")
(setq mp1 (get_midpt pa pb))
(setq mp2 (get_midpt pb pc))
(setq mp3 (get_midpt pc pd))
(setq mp4 (get_midpt pd pa))
(command "line" mp1 mp3 "")
(command "line" mp2 mp4 "")
)
(defun get_midpt(pt1 pt2)
(setq mx (/ (+ (car pt1) (car pt2)) 2))
(setq my (/ (+ (cadr pt1) (cadr pt2)) 2))
(list mx my)
)
代码完。