马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Table styles in AutoCAD are primarily created using the Table Style dialog box (TABLESTYLE command) since there is no command line support, which limits the ability of creating a table style using a script or the COMMAND function in AutoLISP. However, you can leverage the ActiveX API to create or modify table style and cell styles defined in your current drawing.
NOTE: ActiveX API is not available on AutoCAD for Mac.
To create a table style, you must access the ACAD_TABLESTYLE dictionary in the current drawing. Once a reference to the ACAD_TABLESTYLE dictionary is obtained, you can then check to see if a table style already exists using the VLA-GETOBJECT function or add a table style using the VLA-ADDOBJECT function.
The following sample code demonstrates how to create a new table style, but does not check to see if the table style already exists first. If the table style does exist, an error will occur.
- (vl-load-com)
- (defun c:CreateTableStyle ()
- ;; Get the AutoCAD application and current document
- (setq acad (vlax-get-acad-object))
- (setq doc (vla-get-ActiveDocument acad))
- ;; Get the Dictionaries collection and the TableStyle dictionary
- (setq dicts (vla-get-Dictionaries doc))
- (setq dictObj (vla-Item dicts "acad_tablestyle"))
- ;; Create a custom table style
- (setq key "MyTableStyle"
- class "AcDbTableStyle"
- )
- (setq custObj (vla-AddObject dictObj key class))
- ;; Set the name and description for the style
- (vla-put-Name custObj "MyTableStyle")
- (vla-put-Description
- custObj
- "This is my custom table style"
- )
- ;; Sets the bit flag value for the style
- (vla-put-BitFlags custObj 1)
- ;; 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)
- )
|