根据这篇贴子的资料就行了调整:https://hyperpics.blogs.com/beyond_the_ui/2012/07/creating-a-table-style-with-autolisp-and-the-activex-api.html
 - (defun K:CreateTabSty (StyNam MaxTxt MinTxt Margin / dictObj TabSty)
- ;; 获取 Dictionary 集合和 TableStyle 字典
- (setq dictObj (vla-Item (vla-get-Dictionaries (vla-get-activedocument (vlax-get-acad-object))) "acad_tablestyle"))
- (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list dictObj StyNam)))
- (progn
- ;创建自定义表格
- ;(setq StyNam "WorkTools")
- (setq TabSty (vla-AddObject dictObj StyNam "AcDbTableStyle"))
- ;样式名称和注释
- (vla-put-Name TabSty StyNam)
- (vla-put-Description TabSty "用于统计数据")
- ;设置样式的位标志值
- (vla-put-BitFlags TabSty 1)
- ;设置表格的方向,从上到下或从下到上
- (vla-put-FlowDirection TabSty acTableTopToBottom)
- ;; Sets the supression of the table header
- (vla-put-HeaderSuppressed TabSty :vlax-false)
- ;; Sets the supression of the table title
- (vla-put-TitleSuppressed TabSty :vlax-false)
-
- ;水平边距+垂直边距
- (vla-put-HorzCellMargin TabSty Margin)
- (vla-put-VertCellMargin TabSty Margin)
- ;文字居中对齐
- (vla-SetAlignment TabSty (+ acDataRow acTitleRow) acMiddleCenter)
- (vla-SetAlignment TabSty acHeaderRow acMiddleCenter)
- ;|设置标题行和表头行的背景颜色
- (setq colObj (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
- (vla-SetRGB colObj 98 136 213)
- (vla-SetBackgroundColor TabSty (+ acHeaderRow acTitleRow) colObj)
- ;; Release the color object
- (vlax-release-object colObj)
- |;
- ;清除数据行的背景颜色
- (vla-SetBackgroundColorNone TabSty acDataRow :vlax-true)
- ;|
- ;设置标题行底部网格颜色
- (vla-SetRGB colObj 0 0 255)
- (vla-SetGridColor TabSty acHorzBottom acTitleRow colObj)
-
- ;设置标题行的底部网格线线宽
- (vla-SetGridLineWeight TabSty acHorzBottom acTitleRow acLnWt025)
- |;
- ;为数据行和标题行设置可见的网格水平线
- (vla-SetGridVisibility TabSty acHorzInside (+ acHeaderRow acDataRow) :vlax-true)
- ;设置文本样式
- (vla-SetTextStyle TabSty (+ acDataRow acHeaderRow acTitleRow) "Standard")
- ;设置标题、表头和数据行的文本高度
- (vla-SetTextHeight TabSty acTitleRow MaxTxt)
- (vla-SetTextHeight TabSty (+ acDataRow acHeaderRow) MinTxt)
- (setvar 'ctablestyle StyNam)
- )
- (setvar 'ctablestyle StyNam)
- )
- (princ)
- )
用法:
 - (K:CreateTabSty "WorkTools" 5.0 4.0 0.0)
|