.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with AutoCAD Table Plotting '####' in Cells with Formulas

3 REPLIES 3
Reply
Message 1 of 4
nshupeFMPE3
190 Views, 3 Replies

Issue with AutoCAD Table Plotting '####' in Cells with Formulas

(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)

Problem Description

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.

Code Snippet

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;
}

 

Repository

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.

Steps to Reproduce
  1. Open Drawing1.dwg.
  2. Run the AddTable command.
  3. Select the marker in model space and press Enter.
  4. Select a point to insert the new table.
  5. Delete the old table.
  6. Use "Save As" to save the drawing to a new folder (e.g., create a 'test' folder in the same directory as Drawing1.dwg).
  7. 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 '####'.

Temporary Solution

The only workaround I've found is to close and reopen the drawing after running "Save As". This makes the table display correctly.

Question

Is there anything I can do differently in my table generation code to resolve this problem?



Labels (3)
3 REPLIES 3
Message 2 of 4
Gepaha
in reply to: nshupeFMPE3

tb.Cells[tb.Rows.Count - 1, 3].Contents[0].Formula = "%<\\AcExpr (Sum(" + "D3:D" + (tb.Rows.Count).ToString() + "))>%";
Message 3 of 4
nshupeFMPE3
in reply to: Gepaha

@Gepaha 

Thank you for the replay, unfortunately this is what happens with the suggested code

nshupeFMPE3_0-1715809408119.png


Interestingly, when I Save As the formula immediately "corrupts" instead of requiring a Publish

nshupeFMPE3_1-1715809462363.png

 



Message 4 of 4
Gepaha
in reply to: nshupeFMPE3

Strange, I tested your code for the formula and it works correctly.
Is the cell selection range correct?
Have you tried adding the formula through AutoCAD? Does it work correctly?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report