明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 10736|回复: 33

[函数] 简单绘制表格

[复制链接]
发表于 2016-6-1 23:18:12 | 显示全部楼层 |阅读模式
本帖最后由 77077 于 2016-6-1 23:44 编辑
  1. ;;; 简单绘制表格
  2. (defun AddTable (Title datalst RowH / TableList-C2R datalst colms maxrow
  3.                        wlst tabela row colm i
  4.                 )
  5.   (defun TableList-C2R (lst n / l lst)
  6.     (setq l nil)
  7.     (repeat n
  8.       (setq l (cons (mapcar
  9.                       'car
  10.                       lst
  11.                     ) l
  12.               )
  13.             lst (mapcar
  14.                   'cdr
  15.                   lst
  16.                 )
  17.       )
  18.     )
  19.     (reverse l)
  20.   )
  21.   (setq datalst (mapcar
  22.                   '(lambda (y)
  23.                      (mapcar
  24.                        'vl-princ-to-string
  25.                        y
  26.                      )
  27.                    )
  28.                   datalst
  29.                 )
  30.         colms (length datalst)
  31.         maxrow (apply
  32.                  'max
  33.                  (mapcar
  34.                    'length
  35.                    datalst
  36.                  )
  37.                )
  38.         wlst (mapcar
  39.                '(lambda (x)
  40.                   (apply
  41.                     'max
  42.                     (mapcar
  43.                       '(lambda (y)
  44.                          (if y
  45.                            (strlen y)
  46.                            0
  47.                          )
  48.                        )
  49.                       x
  50.                     )
  51.                   )
  52.                 )
  53.                (TableList-C2R datalst maxrow)
  54.              )
  55.         tabela (vla-addTable (vla-get-ModelSpace
  56.                                                  (vla-get-ActiveDocument
  57.                                                                          (vlax-get-acad-object)
  58.                                                  )
  59.                              ) (vlax-3d-point (getpoint "\nPick a point to create the table."))
  60.                              (1+ colms) maxrow RowH (* RowH 50)
  61.                )
  62.   )
  63.   (vla-put-regenerateTableSuppressed tabela :vlax-true)
  64.   (setq i -1)
  65.   (foreach w wlst
  66.     (vla-setcolumnwidth tabela (setq i (1+ i))
  67.                         (* w RowH)
  68.     )
  69.   )
  70.   ; (vla-SetTextStyle tabela (+ acDataRow acHeaderRow acTitleRow) "样式 1")
  71.   (vla-SetTextHeight tabela acTitleRow (* 0.75 RowH))
  72.   (vla-SetTextHeight tabela (+ acDataRow acHeaderRow) (* 0.5 RowH))
  73.   (vla-setalignment tabela acDataRow acMiddleCenter)
  74.   (vla-setText tabela 0 0 Title)
  75.   (setq row 0)
  76.   (foreach data datalst
  77.     (setq row (1+ row)
  78.           colm -1
  79.     )
  80.     (foreach str data
  81.       (vla-setText tabela row (setq colm (1+ colm))
  82.                    str
  83.       )
  84.     )
  85.   )
  86.   (vla-put-regenerateTableSuppressed tabela :vlax-false)
  87.   (princ)
  88. )
  89. (AddTable "TITLE" '(("ValueA0" "ValueA1"
  90.             "ValueA2"
  91.            )
  92.            ("ValueB0" "sdfdsfsdsfsdf1"
  93.             "ValueB2" "ValueB3"
  94.             "ValueB4"
  95.            )
  96.            ("ValueC0" "ValueC1"
  97.             "ValueC2" "ValueC3"
  98.            )
  99.            ("Value5")
  100.           ) 10
  101. )

评分

参与人数 1明经币 +1 收起 理由
自贡黄明儒 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

 楼主| 发表于 2016-6-2 13:28:17 | 显示全部楼层
本帖最后由 77077 于 2016-6-2 13:33 编辑

再来一个line+text
  1. ;|简单绘制表格
  2. 参数:
  3. Title    标题
  4. datalst  表格型的数据
  5. strh     字体高度
  6. LAY      预设图层
  7. 备注:表格型数据需预先处理好,各行长度需相等
  8. 用法示例:
  9. (AddlistTable "这是一个标题"  '(
  10. ("Head11" "Head12" "Head13" "Head14")
  11. ("Value11" "Value12" "Value13" "Value14" "Value15"  "Value16")
  12. ("ValueValue21" "Value22" "Value23" "Value24")
  13. ("Value31" "ValueValueValue32" "Value33" "Value34" "Value35")
  14. ("Value41" "Value42" "Value43" "Value44")
  15. ("Valuen" "Valuen" "Valuen" "ValueValueValueValuen")
  16. ("Valuen" "Valuen" "Valuen" "Valuen")
  17. ("Valuen" "Valuen" "Valuen" "Valuen")
  18. ("Valuen" "Valuen" "Valuen" "Valuen")
  19. ("Valuen" "Valuen" "Valuen" "Valuen")
  20. ("Valuen" "Valuen" "Valuen" "Valuen")
  21. ("Valuen" "Valuen" "Valuen" "Valuen")
  22. ("Valuen" "Valuen" "Valuen" "Valuen")
  23. ("Valuen" "Valuen" "Valuen" "Valuen")
  24. ("Valuen" "Valuen" "Valuen" "Valuen")
  25. ("Valuen" "Valuen" "Valuen" "Valuen")
  26. ("Valuen" "Valuen" "Valuen" "Valuen")
  27. ("Valuen" "Valuen" "Valuen" "Valuen")
  28. ("Valuen" "Valuen" "Valuen" "Valuen")
  29. ("Valuen" "Valuen" "Valuen" "Valuen")
  30. ("Valuen" "Valuen" "Valuen" "Valuen")
  31. )
  32. 5
  33. "TABLE-表格"
  34. )
  35. |;
  36. (defun AddlistTable (Title datalst strh lay / TableList-C2R datalst colms rows wlst PT startx starty endx endy enttable textptxlst nx textptylst ny)
  37.   (defun TableList-C2R (lst n / l lst)
  38.     (setq l nil)  
  39.     (repeat n
  40.       (setq l (cons (mapcar 'car lst) l)
  41.         lst (mapcar 'cdr lst)
  42.       )
  43.     )
  44.     (reverse l)
  45.   )
  46.   (setq colms (length datalst);总行数
  47.     rows (apply 'max (mapcar 'length datalst));总列数
  48.     wlst (mapcar '(lambda(x)(apply 'max (mapcar '(lambda(y) (if y (strlen y) 0)) x)))(TableList-C2R datalst rows));各列最大字符串长度
  49.     wlst (mapcar '(lambda(x) (* (+ x 2) strh)) wlst);各列宽度
  50.     PT (getpoint "\n 指定表格左上角.");左上角
  51.     startx (car pt)
  52.     endx (+ startx (apply '+ wlst))
  53.     starty (cadr pt)
  54.     endy (- starty (* colms strh 2))
  55.   )
  56.   ;绘制竖线,同时计算文字的X表
  57.   (setq textptxlst nil nx startx)
  58.   (entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list nx starty 0.0)) (cons 11 (list nx endy 0.0))))
  59.   (foreach n wlst
  60.     (setq nx (+ nx n)
  61.       textptxlst (cons (- nx (* 0.5 n)) textptxlst)
  62.     )
  63.     (entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list nx starty 0.0)) (cons 11 (list nx endy 0.0))))
  64.   )
  65.   (setq textptxlst (reverse textptxlst))
  66.   ;绘制横线,同时计算文字的Y表
  67.   (setq textptylst nil ny starty)
  68.   (entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list startx ny 0.0)) (cons 11 (list endx ny 0.0))))
  69.   (repeat colms
  70.     (setq ny (- ny strh)
  71.       textptylst (cons ny textptylst)
  72.       ny (- ny strh)
  73.     )
  74.     (entmake (list '(0 . "LINE") (cons 8 lay) (cons 10 (list startx ny 0.0)) (cons 11 (list endx ny 0.0))))
  75.   )
  76.   (setq textptylst (reverse textptylst))
  77.   (entmake (list '(0 . "TEXT") (cons 8 lay) (cons 1 title) (cons 10 (polar pt (* 0.5 pi) strh)) (cons 40 (* strh 1.5))))
  78.   ;写出表格内容
  79.   (mapcar '(lambda(data pty)
  80.              (mapcar '(lambda(str ptx / pt)
  81.                         (if (and str (/= str ""))
  82.                           (progn
  83.                             (setq pt (list ptx pty 0.0))
  84.                             (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)))
  85.                           )
  86.                         );cond
  87.                       )
  88.                data textptxlst
  89.              )
  90.            )
  91.     datalst textptylst
  92.   )
  93.   (princ)
  94. )

点评

高级  发表于 2023-6-14 17:25

评分

参与人数 3明经币 +3 收起 理由
hubeiwdlue + 1 很给力!
JUN1 + 1
1993063 + 1 赞一个!

查看全部评分

回复 支持 2 反对 0

使用道具 举报

 楼主| 发表于 2016-6-2 17:00:58 | 显示全部楼层
自贡黄明儒 发表于 2016-6-2 13:47
通常需要的table表不要第一行"TITLE",删除哪个呀?

(entmake (list '(0 . "TEXT") (cons 8 lay) (cons 1 title) (cons 10 (polar pt (* 0.5 pi) strh)) (cons 40 (* strh 1.5))));写出表格title
回复 支持 1 反对 0

使用道具 举报

发表于 2023-8-6 18:56:11 | 显示全部楼层


  1. (defun c:tt ();普通直线和文本表格
  2.   (setq        lst '(("ValueA0" "ValueA1" "ValueA2")
  3.               ("ValueB0" "1000" "ValueB2" "ValueB3" "ValueB4")
  4.               ("ValueC0" "ValueC1" "ValueC2" "ValueC3")
  5.               ("Value5")
  6.              )
  7.   )
  8.   (xyp-TableAuto '(0 0) lst '("序号" "1" "2" "3" "4" "5"))
  9.   (princ)
  10. )


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2016-6-2 10:55:59 | 显示全部楼层
谢谢楼主分享程序!
发表于 2016-6-2 12:07:33 | 显示全部楼层
(*ERROR* "no function definition: VLA-PUT-REGENERATETABLESUPPRESSED")
你这个与版本有关吧?
 楼主| 发表于 2016-6-2 13:03:54 | 显示全部楼层
自贡黄明儒 发表于 2016-6-2 12:07
(*ERROR* "no function definition: VLA-PUT-REGENERATETABLESUPPRESSED")
你这个与版本有关吧?

删除这两行也影响不大,删除后慢了那么一点点点而已,关闭和打开表格的实时更新。
发表于 2016-6-2 13:47:55 | 显示全部楼层
通常需要的table表不要第一行"TITLE",删除哪个呀?
发表于 2016-6-2 13:51:04 | 显示全部楼层

楼主程序运行的结果如上表,我用arx练练手,结果中下表
bool CCreatEnt::YTMAddGrid(const AcGePoint3d &pt, int a,int b,double height,double width)
{
        //a为几行,b为几列 height为行高,width为列宽
        if(height==NULL || height==0)
        {
                height=2.5;
        }
        if(width==NULL || width==0)
        {
                width=10;
        }
        double x=b*width;
        double y=a*height;
        for(int i= 0;i<=a;i++)
        {
                AcGePoint3d pt1=CCreatEnt::PolarPoint(pt,CCreatEnt::PI()*1.5,i*height);
                AcGePoint3d pt2=CCreatEnt::PolarPoint(pt1,0,x);
                CCreatEnt::YTMAddLine(pt1,pt2);
        }
        for(int i= 0;i<=b;i++)
        {
                AcGePoint3d pt1=CCreatEnt::PolarPoint(pt,0,i*width);
                AcGePoint3d pt2=CCreatEnt::PolarPoint(pt1,CCreatEnt::PI()*1.5,y);
                CCreatEnt::YTMAddLine(pt1,pt2);
        }
        return true;
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

不懂c++,好像是说用户指定行数和列数绘制表格,是固定列宽,没写出文字。  发表于 2016-6-2 17:07
发表于 2016-6-2 13:54:33 | 显示全部楼层
革天明 发表于 2016-6-2 13:51
楼主程序运行的结果如上表,我用arx练练手,结果中下表
bool CCreatEnt::YTMAddGrid(const AcGePoint3d  ...

高手呀,这么简洁。可惜我不懂arx,不然给你加点分
发表于 2016-6-2 14:17:57 | 显示全部楼层
自贡黄明儒 发表于 2016-6-2 13:54
高手呀,这么简洁。可惜我不懂arx,不然给你加点分

这么说可让我惭愧呀!学习arx中,不知道写些什么,就对着练练手,由于版本为Lisp版块,除非题主给出CAD版本,否则我的回答对题主可是没有帮助的。

评分

参与人数 1明经币 +1 收起 理由
Kye + 1

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-24 11:33 , Processed in 0.208848 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表