Skip to content

DXF: a solid or gradient hatch no longer makes AutoCAD refuse the file - #2904

Merged
1 commit merged into
storytold:mainfrom
2ez4gcx:fix/dxf-solid-hatch-groups
Nov 20, 2026
Merged

1 commit merged into
storytold:mainfrom
2ez4gcx:fix/dxf-solid-hatch-groups

Conversation

@2ez4gcx

@2ez4gcx 2ez4gcx commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Since #2665, every DXF that CADCraft writes with a solid or gradient hatch is refused by AutoCAD 2024. AutoCAD discards the whole drawing, not just the hatch:

The following error was encountered while reading
in HATCH starting at line 1496:
Error: expected group code 98
Invalid or incomplete DXF input -- drawing discarded.

#2665 made the writer put groups 52 (pattern angle), 41 (pattern scale) and 77 (double flag) on solid fills too. It said AutoCAD keeps them there, but that wasn't checked in AutoCAD: its fixtures were synthetic files. AutoCAD 2024 writes none of the three on a solid or gradient fill. Its HATCH record goes from 76 straight to 98, and its reader refuses any of the three in that place.

This PR writes 52, 41 and 77 for pattern fills only again, as before #2665. Pattern fills are unchanged.

Measured in AutoCAD 2024

Each file was opened with accoreconsole and its objects counted, or its read error recorded. The drawings are self-built.

File AutoCAD 2024
CADCraft at main (865fa9a): a rectangle, a SOLID hatch, a rectangle, an ANSI31 hatch, saved as DXF refused: expected group code 98
the same with the SOLID hatch's 52 dropped, or its 41, or its 77 (each alone) refused, the same error
the same with all three dropped opened, 4 objects
the same drawing from a CLI built before #2665 (5caaf73) opened, 4 objects
CADCraft at main: a rectangle and a gradient hatch (LINEAR, 30°) refused, the same error
this PR: rectangles with a SOLID, an ANSI31 (30°, scale 2) and a gradient hatch opened, 6 objects. entget shows the ANSI31 at 52 = 0.523599 rad and 41 = 2.0, the gradient as LINEAR, and no 52 or 41 on the solid fills
this PR: a drawing AutoCAD itself wrote with DXFOUT (7 objects, among them a solid hatch), converted by CADCraft opened, 7 objects
a drawing AutoCAD drew itself (22 kinds of object, among them a SOLID and an ANSI31 hatch), saved as DWG, read and written to DXF by CADCraft at main refused: expected group code 98
the same with this PR, DXF and DWG both opened with the same counts by type as AutoCAD's own drawing, and AUDIT Total errors found 0
this PR: a drawing CADCraft drew of 46 objects (lines, arcs, polylines, ellipses, spline, text, MTEXT, 7 dimensions, LEADER, MULTILEADER, three hatches, point, ray, xline, solid, MLINE, helix, wipeout, table, tolerance, region, block with an attribute, INSERT, MINSERT, associative array), DXF and DWG both opened, counts by type matching CADCraft's, AUDIT Total errors found 0

AutoCAD's own DXFOUT of a solid hatch writes 75 76 98 with nothing between 76 and 98.

DWG save isn't affected. It goes through acadrust, and AutoCAD opened CADCraft's DWG of the same drawing (4 objects).

Tests

solid_and_gradient_hatches_have_no_pattern_groups in crates/io/src/tests.rs replaces #2665's solid_hatch_keeps_angle_scale_and_double_flag, which asserted the opposite. It checks:

A mutation run made four changes, and the test caught each one:

  • all three groups written for solid fills, as on main;
  • only 52 written for solid fills;
  • only 77 written for solid fills;
  • 52 and 41 dropped from pattern fills.

Not in this PR

A solid hatch read with an angle and a scale no longer keeps them through a save, which was #2665's aim. AutoCAD doesn't keep them on a solid fill either: entget shows no 52 or 41 there. If they're wanted, CADCraft's own xdata could carry them, but this PR doesn't do that.

Parity row: "HATCH pattern / solid" in docs/file-format-parity.md, as #2665 named it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Solid and gradient hatch exports now omit pattern-specific angle, scale, and double-flag settings. Pattern fills continue to include these settings and their pattern lines.
    • Updated hatch serialization checks confirm that solid and gradient fills omit pattern-only groups while preserving the expected group ordering.

Since storytold#2665 the writer put groups 52, 41 and 77 (pattern angle, scale,
double flag) on solid fills too. AutoCAD 2024 writes none of them there
and refuses a DXF whose solid HATCH has any of them: "Error: expected
group code 98 / Invalid or incomplete DXF input -- drawing discarded".
So every DXF CADCraft saved with a solid or gradient hatch, including an
AutoCAD drawing passed through it, was discarded by AutoCAD. They are
written for pattern fills only again, as before storytold#2665.

Measured in AutoCAD 2024: CADCraft's file with each of the three groups
dropped alone is still refused, with all three dropped it opens; with
this change AutoCAD opens CADCraft's solid, gradient and pattern hatches
and a 46-object drawing, DXF and DWG, with AUDIT reporting 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The HATCH writer now omits pattern angle, scale, and double-flag fields for solid fills. Tests check the serialized fields for solid, gradient, and pattern fills.

Changes: HATCH serialization

Layer / File(s) Summary
Conditional pattern fields
crates/io/src/dxf_write/entity.rs, crates/io/src/tests.rs
The writer emits pattern angle, scale, and double-flag fields only for non-solid hatches. Tests verify that solid and gradient fills omit pattern groups 52, 41, 77, and 78, while pattern fills retain them.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: assamaral

Merge Risk: Minimal · up to 467ab

Solid fills omit pattern-only fields while pattern fills retain them. No merge-blocking risk was established.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title describes the AutoCAD compatibility fix for solid and gradient hatches.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 865fa9a and 467ab20.

Files selected for processing: 2

  • crates/io/src/dxf_write/entity.rs
  • crates/io/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@eliets2 eliets2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First-pass review notes (automated; combined from specialist angles: docs and text). Please treat as suggestions and verify before acting.

Summary: This change writes DXF groups 52, 41 and 77 only for pattern hatches again, omitting them for solid and gradient hatches so the HATCH record goes from 76 directly to 98, and replaces the hatch serialization test to assert that ordering.

Logical units:

  • DXF writer change in write_hatch_entity in crates/io/src/dxf_write/entity.rs to omit 52, 41 and 77 for solid and gradient hatches
  • Test replacement in crates/io/src/tests.rs with solid_and_gradient_hatches_have_no_pattern_groups

Findings:

  • [docs] docs/file-format-parity.md, "HATCH pattern / solid" row: the row still describes the old behavior where solid hatches keep angle, scale and double flag, while write_hatch_entity now omits 52, 41 and 77 for solid and gradient hatches and drops their angle and scale on save. Update the row to state that solid and gradient hatches go from group 76 directly to 98 with no 52, 41, 77 or 78, that pattern hatches keep 52, 41, 77 and 78, and that angle and scale on a solid hatch are not preserved through a save.

Overlaps: None listed.

Verdict: Needs changes. 1) The parity row still describes the old solid-hatch behavior. 2) The row must state solid and gradient hatches go 76 directly to 98 with no 52, 41, 77 or 78, while pattern hatches keep those groups. 3) The row must state angle and scale on a solid hatch are not preserved through a save.

@2ez4gcx

2ez4gcx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I left docs/file-format-parity.md unchanged:

  • AGENTS.md asks PRs not to edit the parity docs: "PRs don't edit these docs: name the affected rows in the PR description, and maintainers update the rows, status lines and revision history in batches". The description names the row ("Parity row: "HATCH pattern / solid" in docs/file-format-parity.md"). Under "Not in this PR" it also says that a solid hatch read with an angle and a scale no longer keeps them through a save.
  • The row on main (a3d9348) doesn't say that solid hatches keep their angle, scale or double flag. It reads | HATCH pattern / solid | yes | yes; associative hatches keep their boundary objects in blocks too, and the boundary carries the hatch reactor (stretched dynamic blocks drag the fill in AutoCAD) | |. This change doesn't make any of that untrue.

freemans32 added a commit to freemans32/cadcraft that referenced this pull request Nov 10, 2026
@multimann

Copy link
Copy Markdown

Independent confirmation from the released build, in case it helps get this merged.

v0.20.1 (7526dc62) still writes 52/41/77 on solid hatches, and AutoCAD 2026 refuses the file the same way (accoreconsole W.164.0.0, AUDIT without fixing).

Minimal repro, one SOLID hatch built with ezdxf 1.4.3:

import ezdxf
doc = ezdxf.new("R2018")
h = doc.modelspace().add_hatch(color=1)   # solid fill
h.paths.add_polyline_path([(0, 0), (10, 0), (10, 10), (0, 10)], is_closed=True)
doc.saveas("solid_hatch_in.dxf")
cadcraft-cli convert solid_hatch_in.dxf solid_hatch_out.dxf

HATCH groups from 97 on:

file groups AutoCAD 2026
input (ezdxf) 97=0 75=0 76=1 98=0 opens, AUDIT 0 errors
written by v0.8.0 97=0 75=0 76=1 98=0 opens, AUDIT 0 errors
written by v0.20.1 97=0 75=0 76=1 52=0.0 41=1.0 77=0 98=0 Error: expected group code 98 … drawing discarded

On a real drawing: an AutoCAD-origin DXF (about 9 MB, roughly a thousand dynamic block references, many solid hatches) written back to DXF by v0.20.1 was refused with the same error. After removing only the 52/41/77 pairs from the solid hatches (70=1), as a text edit, AutoCAD opened it with Total errors found 0. That matches what this PR changes.

DWG save is unaffected here too: AutoCAD 2026 opened v0.20.1's DWG of the same drawing with AUDIT 0 errors.

@2ez4gcx

2ez4gcx commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking this in AutoCAD 2026. It matches what I measured in AutoCAD 2024: the reader refuses 52, 41 or 77 between 76 and 98 on a solid fill, and the same drawing opens once they're gone.

main (ca87680) still writes all three on every solid fill, gradients included (write_hatch_entity in crates/io/src/dxf_write/entity.rs). This branch still merges into it without conflicts, and the cadcraft-io hatch tests pass on that merge, including this PR's solid_and_gradient_hatches_have_no_pattern_groups.

@tanish2k09

Copy link
Copy Markdown
Member

Thank you. This landed through #3346 unchanged; your AutoCAD 2024 measurements and multimann's on 2026 made it easy to land first. It also settles the DXF half of #3303.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants