Community
Hello, I have been able to create a table, populate the Title and Headers with text. Which is all I want it to do for now. The problem is, I can calculate how wide I want each column, but it never gets drawn with the correct column width.
Anyone know how to make it use the correct column width specified? Keep in mind all of the column widths may differ.
Attached is my code.
Public Sub AddTable(ByVal dwg_scale As Double, ByVal dwgTextHeight As Double) Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.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 hdrCellHgt As Double, dtaCellHgt As Double, smdCol0Width As Double, smdCol1Width As Double Dim smdCol2Width As Double, smdCol3Width As Double, smdCol4Width As Double Dim tableLocX As Double, tableLocY As Double, tableLoc As Point3d hdrCellHgt = ((dwgTextHeight * 2) + (dwgTextHeight * 1.5)) 'this is setting the header row height dtaCellHgt = (dwgTextHeight * 2) 'this is setting the title and data row heights smdCol0Width = 13.0 * dwg_scale smdCol1Width = 14.8 * dwg_scale smdCol2Width = 14.8 * dwg_scale smdCol3Width = 19.6 * dwg_scale smdCol4Width = 25.4 * dwg_scale tableLocX = (((smdCol0Width + smdCol1Width + smdCol2Width + smdCol3Width + smdCol4Width) / 2.0) * -1) tableLocY = ((dtaCellHgt * 2) + hdrCellHgt) tableLoc = New Point3d(tableLocX, tableLocY, 0) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.TitleRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.HeaderRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.DataRow) smdTable.Position = tableLoc smdTable.InsertRows(0, dtaCellHgt, 1) smdTable.Rows(0).Style = "Title" smdTable.Cells(0, 0).TextString = "DISCRETE COMPONENTS" smdTable.InsertRows(1, hdrCellHgt, 1) smdTable.InsertRows(2, dtaCellHgt, 1) 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.DeleteRows(3, 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" Dim bt As BlockTable = tableTrans.GetObject(db.BlockTableId, OpenMode.ForRead) Dim smdTableBtr As BlockTableRecord = tableTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) smdTable.GenerateLayout() smdTableBtr.AppendEntity(smdTable) tableTrans.AddNewlyCreatedDBObject(smdTable, True) tableTrans.Commit() End Using End Sub
Try example from this page
http://www.acadnetwork.com/topic-199.0.html