AutoLISP绘制表格
2011-04-05 15:43 精诚所至 金石为开 阅读(926) 评论(0) 编辑 收藏 举报AutoLISP绘制表格,自动绘制表格,代码如下。
(defun c:test()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq pt1 (getpoint "\n第一角点:"))
(setq pt3 (getcorner pt1 "\n另一角点:"))
(command "rectang" "w" 1 pt1 pt3)
(setq wnn (1+ (getint "\n列数|||<5>:")))
(if (null wnn) (setq wnn 5.0))
(setq hnn (1+ (getint "\n行数———<5>:")))
(if (null hnn) (setq hnn 5.0))
(setq pt2 (list (car pt3) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt3)))
(setq ang (angle pt1 pt3))
(cond ((and (> ang 0) (< ang (/ pi 2))) (setq pp1 pt1 pp2 pt2 pp3 pt3 pp4 pt4))
((and (> ang (/ pi 2)) (< ang pi)) (setq pp1 pt2 pp2 pt1 pp3 pt4 pp4 pt3))
((and (> ang pi) (< ang (* pi 1.5))) (setq pp1 pt3 pp2 pt4 pp3 pt1 pp4 pt2))
((and (> ang (* pi 1.5)) (< ang (* pi 2))) (setq pp1 pt4 pp2 pt3 pp3 pt2 pp4 pt1))
)
(setq num 1 txt 65)
(setq ww (distance pp1 pp2))
(setq hh (distance pp1 pp4))
(setq pt1 pp4 ppbas pp4 key 1)
(repeat hnn
(setq pt1 (polar pt1 (* pi 1.5) (/ hh hnn)))
(setq pt2 (polar pt1 0 ww))
(command "line" pt1 pt2 "")
(if (> key 1)
(progn
(setq txtins (inters ppbas (polar pt1 0 (/ ww wnn)) pt1 (polar ppbas 0 (/ ww wnn))))
(command "text" "m" txtins (/ hh hnn 2) 0 (itoa num))
(setq num (1+ num))
)
)
(setq ppbas pt1 key (1+ key))
)
(setq pt1 pp4 ppbas pp4 key 1)
(repeat wnn
(setq pt1 (polar pt1 0 (/ ww wnn)))
(setq pt2 (polar pt1 (* pi 3.5) hh))
(command "line" pt1 pt2 "")
(if (> key 1)
(progn
(setq txtins (inters ppbas (polar pt1 (* pi 1.5) (/ hh hnn)) pt1 (polar ppbas (* pi 1.5) (/ hh hnn))))
(command "text" "m" txtins (/ hh hnn 2) 0 (chr txt))
(setq txt (1+ txt))
)
)
(setq ppbas pt1 key (1+ key))
)
(prin1)
)
代码完。
用默认的提示代码参数类型错误,自己输入就可以。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)