- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I am creating 15 tables with the help of the below code. I am passing a 2d string array for every table. The 2d arrays are getting created and passed correctly. There's a prompt for the user to select the insertion point of the table for each table. When I run the code, the user is asked to enter the insertion point 15 times i.e. for each table, but there's no table created in the model space.
Any help would be appreciated. @norman.yuan @Jeff_M
public static void CreateTable(string[,] str)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointResult pr = ed.GetPoint("\nEnter table insertion point: ");
if (pr.Status == PromptStatus.OK)
{
Autodesk.AutoCAD.DatabaseServices.Table tb = new Autodesk.AutoCAD.DatabaseServices.Table();
tb.TableStyle = db.Tablestyle;
tb.SetSize(str.GetLength(0), str.GetLength(1));
tb.SetRowHeight(50);
tb.SetColumnWidth(130);
tb.Position = pr.Value;
// Use a nested loop to add and format each cell
for (int i = 0; i < tb.Rows.Count; i++)
{
for (int j = 0; j < tb.Columns.Count; j++)
{
string item = str[i, j];
tb.Cells[i, j].TextHeight = 10;
tb.Cells[i, j].TextString = item;
tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
tb.GenerateLayout();
}
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(tb);
tr.AddNewlyCreatedDBObject(tb, true);
tr.Commit();
}
}
}
Thankyou in advance.
Regards,
Priya Mishra
Solved! Go to Solution.