TableEntity cell margin override not honored by AutoCAD on regen

Open
#1,089 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
tooling

Research direction

Start by tracing how TableEntity.Content.CellStyleOverride is serialized into the TABLECONTENT CellStyle block, focusing on spec sections 20.4.97 and 20.4.101.4. Compare ACadSharp's output with the attached reference DWG, then verify that the per-table margins remain after REGEN in AutoCAD without changing the shared TableStyle.

Written by the indexing model from the issue text.

Description

bug

Summary

Writing a TableEntity with a per-table margin override via TableEntity.Content.CellStyleOverride produces a DWG whose table renders correctly when the file is first opened (AutoCAD and DWG TrueView display the override margins), but as soon as the table is regenerated through REGEN in AutoCAD, the margins collapse back to the TableStyle default of 0.06. The initial visual is served from the anonymous block cache ACadSharp writes alongside the table, so the bug is hidden until something forces AutoCAD to rebuild the table from its data.

Reproduction

A single 2x2 TableEntity written at AC1027 (R2013) with:

myTable.CellStyleOverride.HasData = true;
myTable.CellStyleOverride.Type = TableStyle.CellStyleType.FormattedTableData;
myTable.CellStyleOverride.MarginOverrideFlags = TableStyle.MarginFlags.Override;
myTable.CellStyleOverride.HorizontalMargin = 4.0;
myTable.CellStyleOverride.VerticalMargin = 2.0;

renders 4/2 margins in AutoCAD/TrueView at first open, then drops to 0.06 after REGEN. ACadSharp's own DwgReader round-trips the values correctly.

A reference DWG generated by a different DWG writer implementation with the same logical margin values keeps the margins after REGEN. Reading that reference through ACadSharp's DwgReader reports identical raw fields on Content.CellStyleOverride (MarginOverrideFlags = 0x1, HorizontalMargin = 4, VerticalMargin = 2) compared to the ACadSharp output, so both writers appear to target the same logical slot per spec section 20.4.97.

What I tried

Attempt 1 - works but wrong layer

tableStyle.HorizontalCellMargin = eyeTable.HorCellMargin;
tableStyle.VerticalCellMargin = eyeTable.VerCellMargin;

AutoCAD honors the margins through REGEN, but this mutates the shared TableStyle ("Standard"), so any other table that shares the style picks up the same margins. Last writer wins. Not viable for documents with multiple independently-margined tables.

Attempt 2 - does not work

tableStyle.DataCellStyle.MarginOverrideFlags = TableStyle.MarginFlags.Override;
tableStyle.HeaderCellStyle.MarginOverrideFlags = TableStyle.MarginFlags.Override;
tableStyle.TitleCellStyle.MarginOverrideFlags = TableStyle.MarginFlags.Override;

myTable.CellStyleOverride.HasData = true;
myTable.CellStyleOverride.Type = TableStyle.CellStyleType.FormattedTableData;
myTable.CellStyleOverride.MarginOverrideFlags = TableStyle.MarginFlags.Override;
myTable.CellStyleOverride.HorizontalMargin = eyeTable.HorCellMargin;
myTable.CellStyleOverride.VerticalMargin = eyeTable.VerCellMargin;

This mirrors what the reference file looks like through ACadSharp's reader (raw flag pattern matches, margin BD values match). AutoCAD still drops to 0.06 on REGEN. The diff must sit at the bit-stream level inside the CellStyle block in TABLECONTENT (spec section 20.4.97 / 20.4.101.4) rather than at any field ACadSharp surfaces through its reader.

Attached files

  • WriteAutodesk.dwg: Reference DWG produced by another writer (margins survive REGEN)
  • WriteAutodeskNet.dwg: ACadSharp DWG produced with Attempt 2 (margins collapse on REGEN)

Test.zip

Environment

  • ACadSharp branch: master
  • Target version: AC1027
  • Verified with AutoCAD 2025 and DWG TrueView 2025
Dominant language
C#
Stars
873
Forks
223
Avg merge
1d 15h
Merged PRs (30d)
28

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DomCR/ACadSharp

All issues in DomCR/ACadSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.