Login

View Full Version : Row height in Acad tables



MikeJarosz
2007-02-09, 08:59 PM
I am creating a drawing index as an Acad table in 2005. I need to put headers in for Civil, Architectural, structural etc. I want the header to be two merged rows and appear anywhere up and down the table as needed, so I can't use the header row type. Merged cells will work much better for me. My problem is when I merge two cells 8mm high, the merged cell is 18.66667, not the 16.0000 I expected. I thought that the vertical cell margin was the cause of the discrepancy, but making it zero didn't help. Then I thought maybe the cell outline line thickness did it. Nope.

I tried explicitly resetting the row height to 16 after the merge, but still got 18.66667. That number is suspicious: is there some other "invisible" factor affecting the row height of two merged cells?

I want the rows to remain modular so they line up across the page when I need multiple tables.
(the numbers are all in millimeters)




Dim Pspace As AcadPaperSpace
Dim DwgIndex As AcadTable
Dim TemplateFileName As String
Dim Entity As AcadEntity
Dim CurrentRow As Long

'load template drawing
TemplateFileName = "t:testDwgIndex.dwt"
Documents.Add TemplateFileName
Set Pspace = ThisDrawing.PaperSpace

'note: this code will grab the first table it finds!
For Each Entity In ThisDrawing.PaperSpace
If TypeOf Entity Is AcadTable Then
Set DwgIndex = Entity
Exit For
End If
Next Entity
DwgIndex.RecomputeTableBlock False

'rows and cols are zero based
CurrentRow = 4
With DwgIndex
'make 1st header
.MergeCells CurrentRow, (CurrentRow + 1), 0, 2
Debug.Print .GetRowHeight(CurrentRow)
'.SetRowHeight CurrentRow, 16
.SetCellAlignment CurrentRow, 0, acMiddleCenter
.SetCellTextStyle CurrentRow, 0, "titles"
.SetCellTextHeight CurrentRow, 0, 8
.SetText CurrentRow, 0, "HEADER"
CurrentRow = CurrentRow + 2
End With




The debug.print rowheight returns 18.00000001, even though the cells have already been merged.

I would not have used the for...next loop if I could find a better way to grab a table. Apparently there is no AcadTables collection with an Item() property.

zoomharis
2007-02-10, 01:44 PM
I would not have used the for...next loop if I could find a better way to grab a table. Apparently there is no AcadTables collection with an Item() property.
You can use DXF group code value pair to create a collection of AcadTables in the drawing instead of looping through the drawing.

I just rearranged your code and it works fine upto a text height of 6. I think text with height of 8 can not be accommodated in a cell of 16 high ( I tried it manually). Here goes the code...


Dim DwgIndex As AcadTable
Dim TemplateFileName As String
Dim Entity As AcadEntity
Dim CurrentRow As Long
For Each Entity In ThisDrawing.PaperSpace
If TypeOf Entity Is AcadTable Then
Set DwgIndex = Entity
Exit For
End If
Next Entity
DwgIndex.RecomputeTableBlock False
'rows and cols are zero based
CurrentRow = 4
With DwgIndex
.HorzCellMargin = 0
.VertCellMargin = 0
.MergeCells CurrentRow, (CurrentRow + 1), 0, 2
.SetRowHeight CurrentRow, 8
.SetRowHeight CurrentRow + 1, 8
.SetCellTextHeight CurrentRow, 0, 6
.SetCellAlignment CurrentRow, 0, acMiddleCenter
.SetCellTextStyle CurrentRow, 0, "titles"
.SetText CurrentRow, 0, "HEADER"
End With


The interesting thing is that even after merging, CurrentRow refers to the first raw used for merging and CurrentRow+1 refers to the second one. There should be some method for refreshing the table after purging which I was unable to find out. Unfortunately I haven't done anything on AcadTable before.

HTH

MikeJarosz
2007-02-13, 03:28 PM
I found an answer to the table collection problem. VBA allows ANY collection. Heres the code: (abbreviated)


Dim IndexTable as New Collection
For Each Entity In ThisDrawing.PaperSpace
If TypeOf Entity Is AcadTable Then
IndexTable.Add Entity
End If
Next Entity

You can now use ITEM and COUNT with IndexTable

zoomharis
2007-02-13, 04:54 PM
I found an answer to the table collection problem. VBA allows ANY collection. Heres the code: (abbreviated)


Dim IndexTable as New Collection
For Each Entity In ThisDrawing.PaperSpace
If TypeOf Entity Is AcadTable Then
IndexTable.Add Entity
End If
Next Entity

You can now use ITEM and COUNT with IndexTable
I would still suggest you to create a selection set with DXF code value pair "0" and "ACAD_TABLE". It is supposed to be more efficient than iterating through all the AutoCAD entities, especially if the drawing is a huge one. A selection set is basically a collection and has all the properties you mentioned before.

By the way, I hope your cell height problem has already got solved.

HTH.

MikeJarosz
2007-02-15, 02:58 PM
Two problems with the selectionset approach:

a) The drawing is a sheet in paperspace with only 10 entities, five of which are tables
b) I'm reading the files with objectDBX which doesn't allow selection sets

If there were thousands of entities, you have a point about wasting time looping through all of them. The speed of opening drawing files with objectDBX offsets any advantage gained by the selection set method, even though it is faster.

By the way, are you saying the DXF code for tables is 0?

I understand that the DXF codes are built into VB.NET as constants. No more wild goose chases for the DXF code for ellipses.

I solved the row height problem. There was no reason to merge two rows. All I needed to do was merge 3 fields on one line. I could then set that one row to height 16.

zoomharis
2007-02-15, 03:50 PM
By the way, are you saying the DXF code for tables is 0?

No. It's not the way DXF group code value pair work. Basically all unique properties of AutoCAD entities are organised by group codes. In that, group 0 holds the entity type. For AcadTable, this value is ACAD_TABLE. If you want to know more about it, see the article VBA: Working with Selection Set Filters (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=2768231&linkID=2475176) on Autodesk website.



I understand that the DXF codes are built into VB.NET as constants. No more wild goose chases for the DXF code for ellipses.

Yet to see VBA .net . But seriously thinking about it after your thread (http://forums.augi.com/showthread.php?t=55475) on this forum :).



I solved the row height problem. There was no reason to merge two rows. All I needed to do was merge 3 fields on one line. I could then set that one row to height 16.
Now that's clear. Thanks for the feedback.