Argo 发表于 2022-7-5 18:34:38

通过Lisp插入表格

大家好,
 
我目前正在为我的AutoCAD配置文件设置一些自定义。目前,我已经建立了一个Excel表,通过李Mac lisp修改标题栏,这是伟大的。
 
我的下一个任务是在模板文件中使用数据链接设置来轻松创建图纸列表。
 
我已经设置了数据链接以使用excel格式,然后在-table命令中使用该格式。一切都很好,但我目前的问题是,当它拉入文本时,它会将文本缩小100倍。一、 e.11pt文本变为0.11个单位高的文本。
 
我试图解决这个问题的事情有:
 
 
[列表]
[*]将excel中的文本调整得更大以进行补偿(这会导致excel列宽达到其极限,然后会抛出格式并依靠我自己手动更改)
[*]关闭引入excel格式的选项(这会导致单元格对齐松散、合并单元格等,再次导致我不得不手动执行)
[/列表]
有没有一个Lisp程序的人知道,有效地做到了以下几点
 
 
 
[列表=1]
[*]创建带有预设数据链接的表格
[*]将表格中的所有文本按100倍的比例缩放
[/列表]
或者,有一个lisp可以自动调整列宽和行高,以匹配每列中最大的文本字符串等,用于合并单元格。
 
 
 
最终,通过使用-table命令,我能够从一个数据库中引入数据。xlsx文件,与dwg位于同一父文件夹中,但是如果不手动执行,我无法对其进行格式化。
 
 
很高兴提供我的excel格式示例。

Lee Mac 发表于 2022-7-5 18:41:14

你检查过你的桌子样式设置了吗?

Argo 发表于 2022-7-5 18:45:30

嗨,李,
 
是的,我已经设置了一个表格样式,但是我无法应用它,因为excel格式占了上风。当我做以下操作时,我确实尝试过使用表格样式
“关闭引入excel格式的选项(这会导致单元格对齐松散、合并单元格等,再次导致我必须手动执行此操作)”
但无法使表格样式自动设置第一列左对齐、第二列左对齐、第三列居中等。使用表格样式也会取消合并标题行。因此,由于样式选项有限,我转而尝试使用excel格式,因为它更通用。

Argo 发表于 2022-7-5 18:48:45

感谢您的帮助

BIGAL 发表于 2022-7-5 18:53:30

创建表格后,请尝试设置行高和文本高度。
 
看一下关于最后两项的示例代码
 

; custobj is table as a VL object
   ;; Sets the direction of the table, top to bottom or bottom to top
   (vla-put-FlowDirection custObj acTableTopToBottom)

   ;; Sets the supression of the table header
   (vla-put-HeaderSuppressed custObj :vlax-false)

   ;; Sets the horizontal margin for the table cells
   (vla-put-HorzCellMargin custObj 0.22)

   ;; Sets the supression of the table title
   (vla-put-TitleSuppressed custObj :vlax-false)

   ;; Sets the vertical margin for the table cells
   (vla-put-VertCellMargin custObj 0.22)

   ;; Set the alignment for the Data, Header, and Title rows
   (vla-SetAlignment custObj (+ acDataRow acTitleRow) acMiddleLeft)
   (vla-SetAlignment custObj acHeaderRow acMiddleCenter)

   ;; Set the background color for the Header and Title rows
   (setq colObj (vlax-create-object "AutoCAD.AcCmColor.19"))
   (vla-SetRGB colObj 98 136 213)
   (vla-SetBackgroundColor custObj (+ acHeaderRow acTitleRow) colObj)

   ;; Clear the background color for the Data rows
   (vla-SetBackgroundColorNone custObj acDataRow :vlax-true)

   ;; Set the bottom grid color for the Title row
   (vla-SetRGB colObj 0 0 255)
   (vla-SetGridColor custObj acHorzBottom acTitleRow colObj)

   ;; Set the bottom grid lineweight for the Title row
   (vla-SetGridLineWeight tableStyle acHorzBottom acTitleRow acLnWt025)

   ;; Set the inside grid lines visible for the data and header rows
   (vla-SetGridVisibility custObj acHorzInside(+ acDataRow acHeaderRow) :vlax-true)

   ;; Set the text height for the Title, Header and Data rows
   (vla-SetTextHeight custObj acTitleRow 1.5)
   (vla-SetTextHeight custObj (+ acDataRow acHeaderRow) 1.0)

   ;; Set the text height and style for the Title row
   (vla-SetTextStyle custObj (+ acDataRow acHeaderRow acTitleRow) "Standard")

   ;; Release the color object
   (vlax-release-object colObj)
(princ)
)

Argo 发表于 2022-7-5 18:59:17

谢谢Bigal,
 
好的,通过宏,我可以创建带有数据链接的表,并在调用lisp之前将其选中。
 
我知道它的编码很差,但我需要的是一个lisp,它接受当前选择(将是表),并通过您显示的代码编辑数据标题行和标题行。
 
知道将这些更改应用于当前选定表的代码是什么吗

BIGAL 发表于 2022-7-5 19:02:52

发布所需的示例dwg或图像标记更改

Argo 发表于 2022-7-5 19:04:43

附件是一个示例。
 
请注意,我已经从示例中删除了数据链接
 
较小的表格是如何从Excel中导出的,较大的表格是我希望它的外观。
实例图纸

BIGAL 发表于 2022-7-5 19:09:34

看看这个http://knowledge.autodesk.com/support/autocad/getting-started/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Core/files/GUID-CE2CC84F-944A-4EE6-B824-9B81692F5B7B-htm.html
 
看起来您将不得不进行后期处理,正如您所说的那样,Excel覆盖了使用一些示例代码所需的样式。
 

(setq obj (vlax-ename->vla-object (car (entsel)))) ; pick the table
; a couple of globals
(vla-put-height obj 33)
(vla-put-width obj 170)
; do more customising using this method
(vla-setcolumnwidth obj 0 15) ; 0 is first column
(vla-setcolumnwidth obj 1 30)
(vla-setcolumnwidth obj 2 60)

Argo 发表于 2022-7-5 19:15:27

谢谢BIGAL,
 
我设法找到了一些有用的东西。有没有一种方法可以代替选择实体来自动选择最后一个实体。
 
我尝试了entlast,但它没有选择正确的实体。
 
目前,我有一个按钮可以执行以下操作
 
然后,我选择要插入表格的位置,它确实插入了表格,但是如果我使用entlast选项运行lisp,它不会选择最后一个对象。
页: [1] 2
查看完整版本: 通过Lisp插入表格