lisp绘制表格,cad自动生成表格,(第一种手画表格)

  • A+
所属分类:CAD二次开发

在CAD里面表格我知道的有两种,一种是像 excel一样的表格,可以在CAD里面直接导出 excel软件可以直接使用,另一种是直接使用手动画直线绘制,

这里先说说任何使用直线绘制表格吧,使用直线绘制很简单,通过一点计算出各个格子的中心位置和行距列距即可用直线命令绘制出一个列表,只需在每个格子的中心位置使用文字命令在里面填上需要的信息即可,代码很简单,先看看效果图吧!

lisp绘制表格,cad自动生成表格,(第一种手画表格)

如果列数是固定,就写死,不固定需要判断自己的数据有多长,来设置列数,下面是例子是列数是固定的,行数是动态的,

例子:

(defun C:ttb ( / buz k pt kb cir WUS)

;文字位置调试数据
(setq da1 17
da2 39
da3 56
da4 74
da5 95
pt 0
)
;数据格式
(setq DB'(("H01-T01" "200.000" "200" "-995.555" ) ("H02" "D2" "0" "-5" ) ("H03" "D3" 20 "-5" )))

(setq buz (getvar "osmode");捕捉
WUS (getvar "UCSORG");当前坐标位置
)
(command "_ucs" "w");时间坐标

(setq pt(getpoint "\n -->请指定程式表基点位置<网站:huojibk.com>:"))
(setvar "osmode" 0)
(setq AX1(+(car pt) da1)
AX2(+(car pt) da2)
AX3(+(car pt) da3)
AX4(+(car pt) da4)
AX5(+(car pt) da5)
; AX6(+(car pt) da6)
AX7(-(cadr pt) 1)
AX0 pt
K 0
)

(setq AX0(list (car pt) (-(cadr pt) 1)))
(setq da1(list AX1 AX7))
(setq da2(list AX2 AX7))
(setq da3(list AX3 AX7))
(setq da4(list AX4 AX7))
(setq da5(list AX5 AX7))

;固定的表头
(command "_text" "j" "m" AX0 "3" "0" "序号")
(command "_text" "j" "m" da1 "3" "0" "刀号-刀补")
(command "_text" "j" "m" da2 "3" "0" "孔直径")
(command "_text" "j" "m" da3 "3" "0" "孔数量")
(command "_text" "j" "m" da4 "3" "0" "孔深 Z")
(command "_text" "j" "m" da5 "3" "0" "备注")
(setq DB(reverse DB)
bc (length DB));表长
(while (> bc k)

(setq kb(nth k DB))

(setq AX0 (list (car AX0 ) (-(cadr AX0 ) 6) )
da1(list (car da1) (-(cadr da1)6))
da2(list (car da2) (-(cadr da2)6))
da3(list (car da3) (-(cadr da3)6))
da4(list (car da4) (-(cadr da4)6))
da5(list (car da5) (-(cadr da5)6)))

;固定的表数据写对应的位置
(command "_text" "j" "m" AX0 "3" "0" (+ k 1))
(command "_text" "j" "m" da1 "3" "0" (car kb))
(command "_text" "j" "m" da2 "3" "0" (strcat "%%c"(cadr kb)));孔大小
(command "_text" "j" "m" da3 "3" "0" (caddr kb))
(command "_text" "j" "m" da4 "3" "0" (cadr(cdr(cdr kb))))
(command "_text" "j" "m" da5 "3" "0" "--")
(setq K(+ k 1 ))
)
(setq pzx (+(car pt )105)
pzy (+(cadr pt )2)
ptx (-(car pt )5)
pty pzy
)

;画行
(repeat (+ bc 2)
(setq cir(list
'(0 . "LINE");直线
'(62 . 153);颜色
'(6 . "ByBlock");线形
(cons 10(list ptx pzy));起点
(cons 11(list pzx pzy));终点
))
(setq pzy( - pzy 6))

(entmake cir);创建直线
)
(setq pzy( + pzy 6))

;列宽调试数据
(setq da1 10
da2 33
da3 56
da4 67
da5 91
da6 0
k 0
)
;纵向画线,画列
(repeat 7
(setq k(+ k 1))
(setq cir(list
'(0 . "LINE")
'(62 . 153)
'(6 . "ByBlock")
(cons 10(list (+ ptx da6) pty))
(cons 11(list (+ ptx da6) pzy))
))
(entmake cir)
(cond
((= k 1)(setq da6 da1))
((= k 2)(setq da6 da2))
((= k 3)(setq da6 da3))
((= k 4)(setq da6 da4))
((= k 5)(setq da6 da5))
((= k 6)(setq da6 110))
;((= k 7)(setq da6 120))
)

)

(command "_ucs" "n" WUS);还原坐标
(setvar "osmode" buz)
(princ)
)

复制

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: