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
Summary
Writing a
TableEntitywith a per-table margin override viaTableEntity.Content.CellStyleOverrideproduces 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 throughREGENin AutoCAD, the margins collapse back to theTableStyledefault 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
TableEntitywritten at AC1027 (R2013) with:renders 4/2 margins in AutoCAD/TrueView at first open, then drops to 0.06 after
REGEN. ACadSharp's ownDwgReaderround-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'sDwgReaderreports identical raw fields onContent.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
AutoCAD honors the margins through
REGEN, but this mutates the sharedTableStyle("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
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 theCellStyleblock inTABLECONTENT(spec section 20.4.97 / 20.4.101.4) rather than at any field ACadSharp surfaces through its reader.Attached files
REGEN)REGEN)Test.zip
Environment