Private Sub MakeTableStyle()
' creates a TableStyle object
Dim oDict As AcadDictionary
Dim aColor As New AcadAcCmColor
Dim oTblSty As AcadTableStyle
Dim sKeyName As String
Dim sClassName As String
'grab the tablestyle dictionary object
Set oDict = ThisDrawing.Database.Dictionaries.Item("acad_tablestyle")
sKeyName = "Block Table"
sClassName = "AcDbTableStyle"
'create the TableStyle object in the dictionary
Set oTblSty = oDict.AddObject(sKeyName, sClassName)
With oTblSty
.Name = "Excel2Table"
.Description = "Style For The Block Info"
.HorzCellMargin = 0.22
.TitleSuppressed = False
.SetTextHeight 3, 1.3
.SetGridVisibility 3, 3, True
.SetAlignment 3, acMiddleCenter
aColor.SetRGB 244, 0, 0
End With
End Sub
Sub BlockToTable()
Dim oTable As AcadTable
Dim oEnt As AcadEntity
Dim blkRef As AcadBlockReference
Dim varPt As Variant
Dim attVar() As Object
Dim attObj As AcadAttributeReference
Dim row As Long, col As Long
Dim i As Long, j As Long
Dim tmpStr As String
Dim acCol As New AcadAcCmColor
On Error Resume Next
ThisDrawing.Utility.GetEntity oEnt, varPt, vbCrLf & "Select block to import data to table"
If Err Then
Err.Clear
End If
On Error GoTo 0
If Not oEnt Is Nothing Then
If TypeOf oEnt Is AcadBlockReference Then
Set blkRef = oEnt
End If
End If
If Not blkRef.HasAttributes Then
MsgBox "This block does not have an attributes"
Exit Sub
End If
attVar = blkRef.GetAttributes
ReDim blkdata(0 To UBound(attVar) + 1, 0 To 1) As String
blkdata(0, 0) = "Block Name"
If blkRef.IsDynamicBlock Then
blkdata(0, 1) = blkRef.EffectiveName
Else
blkdata(0, 1) = blkRef.Name
End If
For i = 0 To UBound(attVar)
Set attObj = attVar(i)
blkdata(i + 1, 0) = attObj.TagString
blkdata(i + 1, 1) = attObj.TextString
Next i
Dim pt(2) As Double
pt(0) = 0: pt(1) = 0: pt(1) = 0:
Call MakeTableStyle
Set oTable = ThisDrawing.ModelSpace.AddTable(pt, 3, UBound(blkdata, 1) + 1, 5, 30)
oTable.RegenerateTableSuppressed = True
oTable.HorzCellMargin = 0.5
oTable.TitleSuppressed = False
oTable.HeaderSuppressed = False
oTable.SetTextHeight 7, 1.6875
row = 0
col = 0
acCol.SetRGB 143, 189, 164
tmpStr = "Block Attributes Info"
oTable.SetRowHeight row, 22.5
oTable.SetCellTextHeight row, col, 10
oTable.SetCellBackgroundColor row, col, acCol
acCol.SetRGB 173, 43, 0
oTable.SetCellContentColor row, col, acCol
oTable.SetText row, col, tmpStr
oTable.SetCellAlignment row, col, acMiddleCenter
row = 1
col = 0
oTable.SetRowHeight row, 15
For i = 0 To UBound(blkdata, 1)
acCol.SetRGB 236, 237, 238
oTable.SetCellTextHeight row, col, 7.5
oTable.SetCellBackgroundColor row, col, acCol
acCol.SetRGB 0, 0, 180
oTable.SetCellContentColor row, col, acCol
tmpStr = blkdata(i, 0)
oTable.SetColumnWidth i, 80#
oTable.SetText row, col, tmpStr
oTable.SetCellAlignment row, col, acMiddleCenter
acCol.SetRGB 0, 0, 180
col = col + 1
Next
row = 2
col = 0
oTable.SetRowHeight row, 15
For i = 0 To UBound(blkdata, 1)
acCol.SetRGB 236, 237, 238
oTable.SetCellTextHeight row, col, 7.5
oTable.SetCellBackgroundColor row, col, acCol
acCol.SetRGB 0, 0, 180
oTable.SetCellContentColor row, col, acCol
tmpStr = blkdata(i, 1)
oTable.SetText row, col, tmpStr
oTable.SetCellAlignment row, col, acMiddleCenter
col = col + 1
Next
oTable.RegenerateTableSuppressed = False
Set acCol = Nothing
End Sub