Originally Posted by
pcs;[COLOR="Black"
1043651]Sorry, I found another error that created that problem.
Thanks everyone for your help.
In case if somebody else would be interesting to solve this problem
here is a working example that was tested on A2008 only:
Code:
Public Sub addTable()
Dim adoc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = adoc.Editor
Using lock As DocumentLock = adoc.LockDocument()
Dim dbase As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = dbase.TransactionManager.StartTransaction()
Try
Dim arr(,) As String = New String(9, 3) {}
For i As Integer = 0 To UBound(arr, 1)
For j As Integer = 0 To UBound(arr, 2)
arr(i, j) = CStr((i + 1) * (j + 1))
Next
Next
Dim nmRows As Integer = UBound(arr, 1) + 4
Dim nmColumns As Integer = UBound(arr, 2) + 1
Dim position As Point3d = New Point3d(50.0, 25.0, 0.0) 'dummy point
Dim rowHeight As Double = 0.2
Dim blkTbl As BlockTable = CType(trans.GetObject(dbase.BlockTableId, OpenMode.ForRead), BlockTable)
Dim blkTblRec As BlockTableRecord = CType(trans.GetObject(blkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
'Dim styDef As ObjectId = makeTableStyle() 'create table style
Dim myTable As Table = New Table()
myTable.IsHeaderSuppressed = False
myTable.IsTitleSuppressed = False
myTable.NumColumns = nmColumns
myTable.NumRows = nmRows
myTable.Height = nmRows * rowHeight
myTable.Position = position
'myTable.TableStyle = styDef 'set custom table style here
myTable.RecomputeTableBlock(False)
myTable.GenerateLayout()
myTable.SetTextString(0, 0, "Title goes here")
myTable.SetColumnWidth(0, 2)
myTable.SetColumnWidth(1, 3)
myTable.SetColumnWidth(2, 3)
myTable.SetColumnWidth(3, 3)
myTable.SetTextHeight(0.2, RowType.TitleRow) 'title row
myTable.SetTextHeight(0.15, RowType.HeaderRow) 'header row
myTable.SetTextHeight(0.1, RowType.DataRow) 'data row
Dim hdl(3) As String
hdl(0) = "Header A"
hdl(1) = "Header B"
hdl(2) = "Header C"
hdl(3) = "Header D"
For i As Integer = 0 To UBound(hdl)
Dim s As String
s = hdl(i)
myTable.SetTextString(1, i, s)
Next
For i As Integer = 0 To UBound(arr, 1)
For j As Integer = 0 To UBound(arr, 2)
Dim s As String = arr(i, j)
myTable.SetTextString(i + 2, j, s)
Next
Next
'e.g. merge cells in the the very last row
Dim trg As CellRange = New CellRange(nmRows - 1, 0, nmRows - 1, 3)
myTable.MergeCells(trg)
myTable.SetTextString(nmRows - 1, 0, "Merged cells are goes here")
myTable.RecomputeTableBlock(True)
blkTblRec.AppendEntity(myTable)
trans.AddNewlyCreatedDBObject(myTable, True)
ed.Regen()
myTable.Dispose()
blkTbl.Dispose()
blkTblRec.Dispose()
Catch ex As System.Exception
ed.WriteMessage(ex.Message & vbCrLf & ex.StackTrace)
End Try
trans.Commit()
End Using
End Using
End Sub[/COLOR]
~'J'~