Jump to content

Recommended Posts

Posted

HI all,
I am using this lisp to create a custom table style.

(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 "InfoTable"
          class "AcDbTableStyle")
    (setq custObj (vla-AddObject dictObj key class))

    ;; Set the name and description for the style
    (vla-put-Name custObj "InfoTable")
    (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) acMiddleCenter)
    (vla-SetAlignment custObj acHeaderRow acMiddleCenter)

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

    ;; Set the bottom grid lineweight for the Title row
    (vla-SetGridLineWeight custObj 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")

   ;; Set the InfoTable style to use now
    (setvar "ctablestyle" "InfoTable")    

 (princ)
)

But the issue I am facing is that even after changing the value of cell margins,the width of the table cells are very large.

image.thumb.png.d360a704370486526ff37e8d2544d820.png

Can somebody suggest how to solve this issue ? (currently I have to manually adjust the width each time)
I want the width of the column slightly wider than the contents.

Thanks

 

Posted (edited)

The width of the columns of an AutoCAD table is a property of the table object itself, not of the table style. Programmatically, this is dictated by the value of the column width parameter supplied to the AddTable method when creating the table object.

 

If you require the table to have columns of unequal width, you can change the width of each column independently using the SetColumnWidth method of the table object. You may wish to review the code for my LM:AddTable function as used in my Polyline Information program for an example.

Edited by Lee Mac
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...