Jump to content

Insert Table through Lisp


Argo

Recommended Posts

Hi All,

 

I'm currently in the process of setting up some customisations for my AutoCAD profile. At present I have set up an Excel sheet which makes titleblock alterations through a Lee Mac lisp which is great.

 

My next task is to use a datalink setup into my template file to easily create a drawing sheet list table.

 

I have set up the datalink to use the excel formatting which is then used in the -table command. Everything has worked great however my issue at the moment is when it pulls in the text it scales the text down by what seems like a factor of 100. I.e. 11pt text becomes 0.11units high text.

 

Things I have tried to work around this issue are:

 

 

  • Size the text in excel larger to compensate (this then causes excel column widths to hit their limit which then throws out the formatting and relies on myself to alter it manually)
  • Turn off the option to bring in excel formating (this causes me to loose cell alignments, merged cells etc, again resulting in myself having to do it manually)

Is there a lisp anyone knows of that effectively does the following

 

 

 

  1. Creates a Table with a preset data link
  2. Scales all text within the table by a factor of 100

Or alternatively is there a lisp that autosizes column widths and row heights to match the largest text string in each column etc that works with merged cells.

 

 

 

Ultimately by utilising the -table command ive been able to bring in the data from an .xlsx file that lives in the same parent folder as the dwg, however I cannot format it without manually doing it.

 

 

Happy to provide a sample of my excel formatting.

Link to comment
Share on other sites

Hi Lee,

 

Yes i have and ive set up a table style however im unable to apply it as the excel formatting takes over. I did try using table style when I did the following

"Turn off the option to bring in excel formating (this causes me to loose cell alignments, merged cells etc, again resulting in myself having to do it manually)"

but couldnt get the table style to auto set first column to align left, 2nd column left, 3rd centered etc. Using table style also unmerged my title row. Thus due to the limited styling options I reverted to trying to use the excel formatting as it is more versatile.

Edited by Argo
Link to comment
Share on other sites

Try setting row heights and text height after table create.

 

Have a look at this example code about last two items

 

; 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)
)

Link to comment
Share on other sites

Thanks Bigal,

 

Alright so through the macro I can create the table with the data link and have it selected before I call a lisp.

 

I know its poor coding but all i would need then is a lisp which takes the current selection (which will be the table) and edit the data header and title rows though the code you have shown.

 

Any idea what the code is to apply these changes to the currently selected table

Edited by Argo
Link to comment
Share on other sites

Have a look at this http://knowledge.autodesk.com/support/autocad/getting-started/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Core/files/GUID-CE2CC84F-944A-4EE6-B824-9B81692F5B7B-htm.html

 

It looks like you will have to post process as as you say Excel overides the style you will need to play with some of the example code.

 

(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)

Edited by BIGAL
Link to comment
Share on other sites

  • 2 weeks later...

Thanks BIGAL,

 

I've managed to get something to somewhat work. Is there a way rather than selecting the entity to auto select the last entity.

 

I've tried entlast but it doesn't select the right entity.

 

At the moment I have a button that does the following

 

-table;l;Sheet List;

I then select the location to insert the table and it does insert it, however if i then run the lisp using the entlast option it does not select the last object.

Link to comment
Share on other sites

Thanks BIGAL,

 

I'm unsure how to do that but i did try selecting all tables on a specific layer using this code

 

(setq obj (vlax-ename->vla-object (car ( (ssget "x" '((0 . "ACAD_TABLE")(8 . "SHEET_LIST")))))))

but im getting this error

error: bad function: <Selection set: 1312>

Link to comment
Share on other sites

You need to get the zero 0 entry of the selection set the first one, yes they start at 0 not 1.

 

(setq obj (vlax-ename->vla-object (ssname  (ssget "x" '((0 . "ACAD_TABLE")(8 . "SHEET_LIST"))))) 0))

Link to comment
Share on other sites

Thats the portion of code that I am editing at the moment, Ive placed in your code and it now returns a syntax error.

 

(vl-load-com)
(defun c:SheetListEdit()
   ;; Get the AutoCAD application and current document

(setq obj (vlax-ename->vla-object (ssname  (ssget "x" '((0 . "ACAD_TABLE")(8 . "SHEET_LIST")))))0))
 
; a couple of globals
(vla-put-height obj 33)
(vla-put-width obj 170)
; do more customising using this method
(vla-setcolumnwidth obj 0 30) ; 0 is first column
(vla-setcolumnwidth obj 1 90)
(vla-setcolumnwidth obj 2 25)

Link to comment
Share on other sites

I have a theory that its the fact that im trying to select a table that is the issue. Is there any way to select a table, either through defining it and then calling the table in any lsp

Link to comment
Share on other sites

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...