TableEntity cell margin override not honored by AutoCAD on regen
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
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
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)
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DomCR/ACadSharp
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
DWG writer: text styles get the text-style table as their xref block handlePossibly taken @menes97 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 81/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 3 days
-
DwgWriter writes a null shape-file handle for SHAPE entities (WriteShapes = true)Possibly taken @menes97 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
DwgReader reads a color-book entity's Color as ByBlock instead of the book's colorPossibly taken @menes97 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
Similar issues
-
hand-to-AI
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CactuseSecurity/firewall-orchestrator#5803 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug python
Difficulty 1/5 Under an hour Newbie friendliness 88/100
ilia-sokolov/OfficeAgent.NET#89 ·
Maintainers usually reply within 13 days