Issue with AutoCAD Table Plotting '####' in Cells with Formulas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
(The prompt for this post was written by me and fed to ChatGPT in an effort to make it easier to read and diagnose the issue)
I am experiencing an issue when publishing a drawing in AutoCAD. A table created using the AutoCAD API is plotted with '####' in a cell that contains a formula for the Total Sum of a column of lengths.
Below is the main code responsible for creating the table:
private static Table BuildTable(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);
// Insert headers
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;
// Insert data rows
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.LengthTotal;
tb.Cells[irowcount, 3].TextHeight = 0.20;
// Set row height for data
tb.Rows[irowcount].Height = .375;
// Move to the 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)
{
return null;
}
return tb;
}
The rest of the code can be found in this repository: GitHub - WB-nshupe/TableTestShare
The project folder contains a Drawing1.dwg file and a bundle folder with a .dll that includes one command, AddTable. I've minimized the code in the plugin to isolate the issue.
- Open Drawing1.dwg.
- Run the AddTable command.
- Select the marker in model space and press Enter.
- Select a point to insert the new table.
- Delete the old table.
- Use "Save As" to save the drawing to a new folder (e.g., create a 'test' folder in the same directory as Drawing1.dwg).
- Without closing or saving the file, select both layouts and publish.
The generated PDF will show the table with '####' in the cells, and the table in paper space will also have '####'.
The only workaround I've found is to close and reopen the drawing after running "Save As". This makes the table display correctly.
Is there anything I can do differently in my table generation code to resolve this problem?