AutoCAD LISP利用子程序绘制田字格
2011-03-27 13:35 精诚所至 金石为开 阅读(750) 评论(0) 编辑 收藏 举报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)
)
代码完。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)