Inserted Table causing crash after saving,closing then reopening
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I have a table that was generated using this code
public static Table BuildTable(Transaction Trans, String title, List<String> headers, Point3d insertPoint, LoopDataCollection tabledata)
{
Table tb = new Table();
try
{
tb.Position = insertPoint;
tb.TableStyle = Active.Database.Tablestyle;
tb.SetSize(tabledata.Count + 3, 1);
tb.SetRowHeight(.5);
tb.SetColumnWidth(1.5);
tb.Cells[0, 0].SetValue(title, ParseOption.ParseOptionNone);
tb.Cells[0, 0].TextHeight = .22;
//Set the width of the columns
tb.InsertColumns(0, 1.00, 1);
tb.InsertColumns(0, 1.625, 1);
tb.InsertColumns(0, 1.5, 1);
//for each Header
int irowcount = 1;
int icolcount = 0;
foreach (String header in headers)
{
tb.Cells[irowcount, icolcount].SetValue(header, ParseOption.ParseOptionNone);
tb.Cells[irowcount, icolcount].TextHeight = 0.20;
icolcount++;
}
//Set header row height
tb.Rows[irowcount].Height = .50;
//for each Data row
irowcount = 2;
foreach (LoopMarkerData loop in tabledata)
{
tb.Cells[irowcount, 0].SetValue(loop.ZoneId, ParseOption.ParseOptionNone);
tb.Cells[irowcount, 0].TextHeight = 0.20;
tb.Cells[irowcount, 1].SetValue(loop.Manifold, ParseOption.ParseOptionNone);
tb.Cells[irowcount, 1].TextHeight = 0.20;
tb.Cells[irowcount, 2].SetValue(loop.Loop, ParseOption.ParseOptionNone);
tb.Cells[irowcount, 2].TextHeight = 0.20;
tb.Cells[irowcount, 3].TextString = loop.Length;
tb.Cells[irowcount, 3].TextHeight = 0.20;
// Set row height for data
tb.Rows[irowcount].Height = .375;
//next row
irowcount++;
}
//Add Totals
tb.Cells[tb.Rows.Count - 1, 1].SetValue("Total", ParseOption.ParseOptionNone);
tb.Cells[tb.Rows.Count - 1, 1].TextHeight = 0.25;
tb.Cells[tb.Rows.Count - 1, 3].Contents.Add();
tb.Cells[tb.Rows.Count - 1, 3].Contents[0].Formula = "=Sum(D3:D" + (tb.Rows.Count - 1) + ")";
//Generate the layout
tb.GenerateLayout();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Active.WriteMessage("\nError in UtilitiesHNC.BuildTable: " + ex.Message);
_fail = true;
Trans.Abort();
}
catch (System.Exception ex)
{
Active.WriteMessage("\nError in UtilitiesHNC.BuildTable: " + ex.Message);
_fail = true;
Trans.Abort();
}
return tb;
}
The file attached with the title "test_made_in_old_tools.dwg" has a working table, which is not causing any problems.
But if I use this code, I get a table that "works". But if I save and close the file, then reopen the file, I get a table where the formula cell is blank, and will crash my cad if clicked on
public static Table BuildTable(string title, List<string> headers, Point3d insertPoint, LoopDataCollection tableData)
{
/*
*Table gets created with default 1 row and 1 column
* so when inserting default rows and columns, remove old row and column
* which get pushed to the last index
*/
Table tb = new Table();
try
{
tb.Position = insertPoint;
tb.Layer = LayerName;
tb.TableStyle = Active.Database.Tablestyle;
int zoneCol = 0, manifoldCol = 1, loopCol = 2, lengthCol = 3;
int titleRow = 0, headersRow = 1, totalRow = 2;
tb.InsertColumns(0, 1.5, 4);
tb.DeleteColumns(tb.Columns.Count - 1, 1);//deletes the default column
tb.SetColumnWidth(1.5);
tb.Columns[manifoldCol].Width = 1.63;
tb.Columns[loopCol].Width = 1;
tb.InsertRows(0, .5, 3);
tb.DeleteRows(tb.Rows.Count - 1, 1);
tb.SetRowHeight(.5);
tb.Cells.TextHeight = .19;//main text height
//Title row
CellRange titleRange = CellRange.Create(tb, titleRow, zoneCol, titleRow, lengthCol);
tb.MergeCells(titleRange);
tb.Rows[titleRow].TextHeight = .25;//bigger title
tb.Cells[titleRow, 0].TextString = title;
tb.Rows[titleRow].Alignment = CellAlignment.MiddleCenter;
////headers row
tb.Cells[headersRow, zoneCol].TextString = "ZONE";
tb.Cells[headersRow, manifoldCol].TextString = "MANIFOLD";
tb.Cells[headersRow, loopCol].TextString = "LOOP";
tb.Cells[headersRow, lengthCol].TextString = "LENGTH";
tb.Rows[headersRow].Alignment = CellAlignment.MiddleCenter;
foreach (LoopMarkerData data in tableData)
{
int row = tb.Rows.Count - 1;
tb.InsertRows(row, .38, 1);
tb.Cells[row, zoneCol].SetValue(data.ZoneId, ParseOption.SetDefaultFormat);
tb.Cells[row, manifoldCol].SetValue(data.Manifold, ParseOption.SetDefaultFormat);
tb.Cells[row, loopCol].SetValue(data.Loop, ParseOption.SetDefaultFormat);
tb.Cells[row, lengthCol].TextString = data.LengthTotal;
}
////total row
int bottomRow = tb.Rows.Count - 1;
tb.Cells[bottomRow, manifoldCol].TextString = "TOTAL";
tb.Cells[tb.Rows.Count - 1, 3].Contents.Add();
tb.Cells[tb.Rows.Count - 1, 3].Contents[0].Formula = "=Sum(D3:D" + (tb.Rows.Count - 1) + ")";
tb.GenerateLayout();
}
catch (Exception ex)
{
Active.WriteMessage($"\nError in {nameof(BuildTable)}: {ex.Message}");
return null;
}
return tb;
}
The file labeled "broken_test_in_old_tools.dwg" has the working table, and the "broken" table. I'm really at a loss for what could be causing the problem, and when I click the cell that is suppose to have the formula but doesn't, AutoCAD crashes without any prompt for a stack trace or anything.
Thanks for any help.
Link copied