Your code is working good enough not ideal though sorry
Here is just quickly edited attempt of mine
Here is nap time for me so I can't to rewrite it completely
Try this out:
{code}
Public Sub AddTable(ByVal dwg_scale As Double, ByVal dwgTextHeight As Double) Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor
Using tableTrans As Transaction = db.TransactionManager.StartTransaction() Dim txtTbl As TextStyleTable = tableTrans.GetObject(db.TextStyleTableId, OpenMode.ForRead) Dim smdTable As New Table() smdTable.TableStyle = db.Tablestyle Dim tblStyle As TableStyle = tableTrans.GetObject(smdTable.TableStyle, OpenMode.ForWrite) Dim cellHgt As Double, smdCol0Width As Double, smdCol1Width As Double Dim smdCol2Width As Double, smdCol3Width As Double, smdCol4Width As Double, tableLocX As Double, tableLoc As Point3d
cellHgt = dwgTextHeight * 2 smdCol0Width = 9.0 * dwg_scale smdCol1Width = 13.5 * dwg_scale smdCol2Width = 13.5 * dwg_scale smdCol3Width = 16.2 * dwg_scale smdCol4Width = 21.3 * dwg_scale tableLocX = (((smdCol0Width + smdCol1Width + smdCol2Width + smdCol3Width + smdCol4Width) / 2.0) * -1) tableLoc = New Point3d(tableLocX, 0, 0)
tblStyle.SetTextStyle(txtTbl("Romans"), RowType.TitleRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.HeaderRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.DataRow) smdTable.Rows(0).Style = "Title" smdTable.Position = tableLoc smdTable.Cells(0, 0).TextString = "DISCRETE COMPONENTS" smdTable.InsertRows(1, cellHgt, 2) smdTable.InsertColumns(0, smdCol0Width, 1) smdTable.InsertColumns(1, smdCol1Width, 1) smdTable.InsertColumns(2, smdCol2Width, 1) smdTable.InsertColumns(3, smdCol3Width, 1) smdTable.InsertColumns(4, smdCol4Width, 1) smdTable.DeleteColumns(5, 1) smdTable.Rows(1).Style = "Header" smdTable.Rows(1).TextHeight = dwgTextHeight smdTable.Rows(2).Style = "Data" smdTable.Rows(2).TextHeight = dwgTextHeight smdTable.Rows(1).Alignment = CellAlignment.MiddleCenter smdTable.Rows(2).Alignment = CellAlignment.MiddleCenter smdTable.Cells.Alignment = CellAlignment.MiddleCenter smdTable.Cells.TextHeight = dwgTextHeight smdTable.Cells(1, 0).TextString = "ITEM NO." smdTable.Cells(1, 1).TextString = "X" smdTable.Cells(1, 2).TextString = "Y" smdTable.Cells(1, 3).TextString = "Z (HEIGHT)" smdTable.Cells(1, 4).TextString = "COMPONENT TYPE" smdTable.Cells(2, 0).TextString = 1 smdTable.Cells(2, 1).TextString = 1.2345 smdTable.Cells(2, 2).TextString = 2.3456 smdTable.Cells(2, 3).TextString = 0.0 smdTable.Cells(2, 4).TextString = "SOME TYPE" Dim bt As BlockTable = tableTrans.GetObject(db.BlockTableId, OpenMode.ForRead) Dim smdTableBtr As BlockTableRecord = tableTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
smdTableBtr.AppendEntity(smdTable) tableTrans.AddNewlyCreatedDBObject(smdTable, True) tableTrans.Commit()
End Using
End Sub
{code}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919