lisp画靶子 visual_简单绘制表格 - AutoLISP/Visual LISP 编程技术 - CAD论坛 - 明经CAD社区 - Powered by Discuz!...

本文介绍了一种使用LISP语言简单绘制表格的方法,通过定义函数AddlistTable,可以快速创建具有指定标题和数据的表格。表格数据需要预先处理,确保同行长度相等。该函数会根据数据自动生成表格线条,并放置文字。
摘要由CSDN通过智能技术生成

本帖最后由 77077 于 2016-6-2 13:33 编辑

再来一个line+text[code="lisp]

;|简单绘制表格

参数:

Title    标题

datalst  表格型的数据

strh     字体高度

LAY      预设图层

备注:表格型数据需预先处理好,各行长度需相等

用法示例:

(AddlistTable "这是一个标题"  '(

("Head11" "Head12" "Head13" "Head14")

("Value11" "Value12" "Value13" "Value14" "Value15"  "Value16")

("ValueValue21" "Value22" "Value23" "Value24")

("Value31" "ValueValueValue32" "Value33" "Value34" "Value35")

("Value41" "Value42" "Value43" "Value44")

("Valuen" "Valuen" "Valuen" "ValueValueValueValuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

("Valuen" "Valuen" "Valuen" "Valuen")

)

5

"TABLE-表格"

)

|;

(defun AddlistTable (Title datalst strh lay / TableList-C2R datalst colms rows wlst PT startx starty endx endy enttable textptxlst nx textptylst ny)

(defun TableList-C2R (lst n / l lst)

(setq l nil)

(repeat n

(setq l (cons (mapcar 'car lst) l)

lst (mapcar 'cdr lst)

)

)

(reverse l)

)

(setq colms (length datalst);总行数

rows (apply 'max (mapcar 'length datalst));总列数

wlst (mapcar '(lambda(x)(apply 'max (mapcar '(lambda(y) (if y (strlen y) 0)) x)))(TableList-C2R datalst rows));各列最大字符串长度

wlst (mapcar '(lambda(x) (* (+ x 2) strh)) wlst);各列宽度

PT (getpoint "\n 指定表格左上角.");左上角

startx (car pt)

endx (+ startx (apply '+ wlst))

starty (cadr pt)

endy (- starty (* colms strh 2))

)

;绘制竖线,同时计算文字的X表

(setq textptxlst nil nx startx)

(entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list nx starty 0.0)) (cons 11 (list nx endy 0.0))))

(foreach n wlst

(setq nx (+ nx n)

textptxlst (cons (- nx (* 0.5 n)) textptxlst)

)

(entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list nx starty 0.0)) (cons 11 (list nx endy 0.0))))

)

(setq textptxlst (reverse textptxlst))

;绘制横线,同时计算文字的Y表

(setq textptylst nil ny starty)

(entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list startx ny 0.0)) (cons 11 (list endx ny 0.0))))

(repeat colms

(setq ny (- ny strh)

textptylst (cons ny textptylst)

ny (- ny strh)

)

(entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list startx ny 0.0)) (cons 11 (list endx ny 0.0))))

)

(setq textptylst (reverse textptylst))

(entmake (list '(0 . "TEXT") (cons 8 lay) (cons 1 title) (cons 10 (polar pt (* 0.5 pi) strh)) (cons 40 (* strh 1.5))))

;写出表格内容

(mapcar '(lambda(data pty)

(mapcar '(lambda(str ptx / pt)

(if (and str (/= str ""))

(progn

(setq pt (list ptx pty 0.0))

(entmake (list '(0 . "TEXT") (cons 8 lay) (cons 1 str)(cons 10 pt) (cons 40 strh) (cons 11 pt) (cons 72 1) (cons 73 2)))

)

);cond

)

data textptxlst

)

)

datalst textptylst

)

(princ)

)[/code]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值