Hi Mr. Ambrosl,
thank you for the code in reply to my post, but I have not seen any effect on my table contents.
Probably there is something of wrong in my initial code (here below reported with also your code part inserted).
I'll try to explain below code functionality:
I have a drawing which contains a lot of blocks, each block contain some Attributes, attributes are extracted from blocks and listed in a table inside the drawing. In a first time I was producing an external excel file, without any kind of problem, but each time I made a modification on drawing I have also to update excel file. On the opposite with a table part of drawing I have to update only table data inside the drawing.
In this case the main issue, as explained in my initial post, is to adapt the columns width to cell contents.
So, if SetAutoScale2 functionality could be compared with excel column adapting functionality it should work, and can be used for my scope, if not I have to fix manually the columns width after data has been filled.
Sub ProvaTabellaBlocchi()
Dim minp As Variant
Dim maxp As Variant
Dim pt(2) As Double
Dim acTable As AcadTable
Dim zz As Long
pt(0) = 5700#
pt(1) = 1250#
ColNr = 0
Rownr = 2
Set acTable = ThisDrawing.ActiveLayout.Block.AddTable(pt, 70, 12, 5, 60)
'AcTable.SetColumnWidth 2, 95
With acTable
.Layer = "GS - TABLE"
.StyleName = "GLASS SERVICE"
.RegenerateTableSuppressed = True
.RecomputeTableBlock False
.TitleSuppressed = False
.HeaderSuppressed = False
.SetTextStyle AcRowType.acTitleRow, "GS - Testo" '<-- change text style name here
.SetTextStyle AcRowType.acHeaderRow, "GS - Testo"
.SetTextStyle AcRowType.acDataRow, "GS - Testo"
.HorzCellMargin = 4 '2
.VertCellMargin = 0.5
Dim i As Double, j As Double
Dim MyCol As New AcadAcCmColor
MyCol.SetRGB 255, 0, 0
.SetText 1, 0, "TAG"
.SetText 1, 1, "LOOP"
.SetText 1, 2, "DESCRIPTION"
.SetText 1, 3, "TAG"
.SetText 1, 4, "LOOP"
.SetText 1, 5, "DESCRIPTION"
.SetText 1, 6, "TAG"
.SetText 1, 7, "LOOP"
.SetText 1, 8, "DESCRIPTION"
.SetText 1, 9, "TAG"
.SetText 1, 10, "LOOP"
.SetText 1, 11, "DESCRIPTION"
'.ColumnWidth
'title
.SetCellTextHeight i, j, 8
.SetCellAlignment i, j, acMiddleCenter
'MyCol.SetRGB 194, 212, 235
'.SetCellBackgroundColor i, j, MyCol
MyCol.SetRGB 255, 0, 0
.SetCellContentColor i, j, MyCol
.SetCellType i, j, acTextCell
.SetText 0, 0, "LOOP REFERENCE & DESCRIPTION"
i = i + 1
'headers
For j = 0 To .Columns - 1
'MyCol.SetRGB 203, 220, 183
'.SetCellBackgroundColor i, j, MyCol
MyCol.SetRGB 255, 0, 0
.SetCellContentColor i, j, MyCol
.SetCellTextHeight i, j, 5
.SetCellAlignment i, j, acMiddleCenter
.SetCellType i, j, acTextCell
Next
'.SetText i, j, "Header" & CStr(j + 1)
j = 0
For i = 2 To .Rows - 1
For j = 0 To .Columns - 1
.SetCellTextHeight i, j, 3
.SetCellAlignment i, j, acMiddleCenter
.SetRowHeight i, 3
If i Mod 2 = 0 Then
MyCol.SetRGB 255, 0, 0
Else
MyCol.SetRGB 255, 0, 0
End If
'.SetCellBackgroundColor i, j, MyCol
'MyCol.SetRGB 0, 76, 0
.SetCellContentColor i, j, MyCol
.SetCellType i, j, acTextCell
Next j
Next i
For i = 2 To .Rows - 1
For j = 0 To .Columns - 1
.SetAutoScale i, j, False = False
Next j
Next i
'Estrae Blocchi
For Each Entity In ThisDrawing.ModelSpace
'Set Block = Entity
If TypeOf Entity Is AcadBlockReference Then
'If Entity.ObjectName = "AcDbBlockReference" Then
If Entity.Name = "COMPONENT TAG" Then
If Entity.HasAttributes = True Then
ListaAtt = Entity.GetAttributes
'PuntoInser = Entity.InsertionPoint
acTable.SetText Rownr, ColNr, ListaAtt(0).TextString
acTable.SetText Rownr, ColNr + 1, ListaAtt(1).TextString
acTable.SetText Rownr, ColNr + 2, ListaAtt(2).TextString
'AcTable.SetAutoScale 2, ColNr, True = True
'AcTable.SetAutoScale 2, ColNr + 1, True = True
'AcTable.SetAutoScale 2, ColNr + 2, True = True
Rownr = Rownr + 1
If Rownr >= 70 Then
Rownr = 2
ColNr = ColNr + 3
End If
'Entity.Delete
End If
End If
End If
Next Entity
' set color for grid
MyCol.SetRGB 255, 255, 255
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acVertInside, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acVertRight, AcRowType.acTitleRow, MyCol
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acVertInside, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acVertRight, AcRowType.acHeaderRow, MyCol
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acDataRow, MyCol
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acDataRow, MyCol
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acDataRow, MyCol
.SetGridColor AcGridLineType.acVertInside, AcRowType.acDataRow, MyCol
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acDataRow, MyCol
.SetGridColor AcGridLineType.acVertRight, AcRowType.acDataRow, MyCol
'set line weights for grid
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acTitleRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acTitleRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acTitleRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acHeaderRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acDataRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acDataRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acDataRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acDataRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acDataRow, AcLineWeight.acLnWt000
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acDataRow, AcLineWeight.acLnWt000
End With
'Dim acTable As AcadTable
Dim acEnt As AcadEntity
' Step through all entities in Model space
'For Each acEnt In ThisDrawing.ModelSpace
' Check to see if the entity is a Table
'If acEnt.ObjectName = "AcDbTable" Then
' Set acTable = acEnt
Dim nRow As Integer, nCol As Integer
nRow = 0
' Step through each row in the table
Do While acTable.Rows > nRow
nCol = 0
' Step through each column
Do While acTable.Columns > nCol
' Set the AutoScale value for each cell based on the content in
' index 0, the first content in each cell
acTable.SetAutoScale2 nRow, nCol, 0, True
nCol = nCol + 1
Debug.Print "nCol "; nCol
Loop
nRow = nRow + 1
Debug.Print "nRow "; nRow
Loop
' End If
' Next acEnt
acTable.RegenerateTableSuppressed = False
acTable.RecomputeTableBlock True
acTable.Update
acTable.GetBoundingBox minp, maxp
ZoomWindow minp, maxp
ZoomScaled 0.9, acZoomScaledRelative
ThisDrawing.SetVariable "LWDISPLAY", 1
Set MyCol = Nothing
MsgBox "finito"
End Sub