Skip to content

DWG: AutoCAD 2027's materials kept through DWG; its test drawings on main - #29

Merged
withshalom merged 3 commits into
mainfrom
claude/gifted-franklin-wtt1ma
Nov 18, 2026
Merged

withshalom merged 3 commits into
mainfrom
claude/gifted-franklin-wtt1ma

Conversation

@withshalom

Copy link
Copy Markdown
Member

What

draftcraft-cli roundtrip in strict mode, run on AutoCAD 2027's test drawings (crates/io/tests/data/acad-solids), reported 3 MATERIAL objects "lost on save, not written" for DXF → DWG in almost every file. The same three materials (ByLayer, ByBlock, Global) are in every drawing AutoCAD makes, 2D included. Two problems:

  • DXF → DWG: AutoCAD 2027's DXF gives a material's group only when its value isn't AutoCAD's default, so there are no map sources, only the matrices that aren't the identity, and 94 63. The encoder only accepted the longer form an older AutoCAD wrote (72 0 …, all six matrices), so it gave up.
  • DWG → DWG: this didn't work either, contrary to what the report suggests. The decoder's fixed bit runs didn't match AutoCAD 2027's records, so opening its DWG dropped the three materials ("MATERIAL (not decoded) × 3"). The ACAD_MATERIAL dictionary then shrank and $CMATERIAL was lost. The roundtrip's DWG → DWG route only showed nothing lost on save because the materials never reached the writer.

The fix

crates/dwg/src/read/styles.rs: the MATERIAL record is now read and written field by field. Each map is its blend, projection, tiling, automatic transform and matrix, then its source and, for an image file, the file; from 2007 the channels follow. AutoCAD 2027 gives each map an image file as its source (with no file named) and channels 63; the older AutoCAD used the scene (0) and 127.

  • A group the DXF leaves out holds AutoCAD's default (source 1, the identity, 127), and decoding leaves the defaults out, as AutoCAD's DXF does.
  • Every other field must be at AutoCAD's default. Otherwise the material is left out and counted, as before: no guessing, no panics.
  • Every material record in AutoCAD 2027's DWG files (2000, 2004, 2007, 2010, 2013, 2018) and in mi201's parses with no bit left over.

The test drawings on main

The acad-solids drawings (50 DWG/DXF files and their two READMEs) are copied unchanged from the 3D branch. Their ATTRIBUTION.md rows sit in the same place, so merging main into 3D sees the same change on both sides. Only DWG/DXF tests use them here; the 3D tests stay on 3D.

Tests

  • Codec (styles.rs): writes AutoCAD 2027's ByLayer record bit for bit (2000 and 2018) and reads it back. Materials keep their groups through every version. A material the codec can't hold is an error both ways.
  • crates/io/tests/it/style_objects_dwg.rs: AutoCAD 2027's DWG files read their materials as its DXF of that version gives them, and its DXF saved as DWG of every version reads back the same. Both tests fail without the fix.
  • Strict roundtrip on acad-solids: 29 findings → 22, none of them MATERIAL. The rest (MESH, the surfaces, ACSH_*, ACDB*PERSSUBENTMANAGER, ACDBASSOC*) are left out and counted, never a crash; they're written up for the 3D work.

Also

  • crates/engine/tests/it/arc_ctrl_direction.rs: clippy 1.97 refuses d < x || d > y (manual_range_contains). Its suggested fix would change the result for a NaN angle, so the line uses an equivalent form instead.

Checks

cargo xtask ci: fmt, clippy, i18n, assets, layers and wasm pass, and the full test suite passes except gpu_viewport_stencil::clipped_viewport_contents_draw_only_inside_their_outline, which needs a graphics adapter the container doesn't have ("No adapter found").

Not in this PR (found along the way)

  • The DWG reader drops the extended data of the objects it keeps (object_tags in crates/io/src/dwg/carry.rs). For example, the Global material's ACAD data is in AutoCAD's DWG and in DraftCraft's, but not in the drawing either opens to.
  • Materials get new handles on DXF → DXF and DXF → DWG (already so before this change), so $CMATERIAL points at nothing and is lost.

Generated by Claude Code

The AutoCAD 2027 test drawings of the 3D work (crates/io/tests/data/
acad-solids, 50 drawings and their two READMEs) are DWG and DXF
reference files for main's DWG and DXF work as well. Copied unchanged
from the 3D branch, with their ATTRIBUTION.md rows in the same place,
so merging main into 3D sees the same change on both sides. The tests
that use them for 3D stay on the 3D branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F67RstRyPmyUTMJji65UEF
The MATERIAL codec held AutoCAD's default materials as fixed bit runs
taken from an older AutoCAD's files, whose maps have the scene as their
source. AutoCAD 2027 gives each map an image file as its source (with
no file named) and its own channels (63), so its DWG materials were not
decoded (lost on opening) and its DXF ones, which give a group only
when the value is not the default, were not encoded (lost on saving as
DWG): ByLayer, ByBlock and Global, in every drawing.

The record is now read and written by its fields: each map's blend,
projection, tiling, automatic transform, matrix, then its source and,
for an image file, the file; from 2007 the channels. A group the DXF
leaves out holds AutoCAD's default (source 1, the identity, 127
channels), and decoding leaves the defaults out as AutoCAD's DXF does.
Every other field must be AutoCAD's default, or the material is left
out and counted, as before. Every material record of AutoCAD 2027's
and of mi201's DWG files (2000 to 2018) is accounted for bit by bit.

Tests: the codec writes AutoCAD 2027's ByLayer record bit for bit
(2000 and 2018) and reads it back; materials keep their groups through
every version; a material it can't hold is an error both ways.
AutoCAD 2027's DWG files read as its DXF gives them, and its DXF saved
as DWG of every version reads back the same (both fail without the
fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F67RstRyPmyUTMJji65UEF
Clippy 1.97 refuses `d < x || d > y` in `same_angle`. Its suggestion
would make a NaN angle compare equal; the distance to the nearest full
turn keeps the old result for every input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F67RstRyPmyUTMJji65UEF
withshalom pushed a commit that referenced this pull request Nov 18, 2026
For Codie: the 22 strict-roundtrip findings left after the MATERIAL fix
(#29): MESH, the surfaces, AutoCAD's
solid-history (ACSH_*), persistent-subentity managers and associative
(ACDBASSOC*) objects. What happens to them now (left out and counted,
never a crash, lost on DWG open as well as on DXF -> DWG save), where
the work goes (main, per the owner's decision and AGENTS.md), the
method that found the MATERIAL layout, an order to take them in, and
two related gaps on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F67RstRyPmyUTMJji65UEF
@withshalom
withshalom marked this pull request as ready for review November 18, 2026 19:26
@withshalom
withshalom merged commit 9ac4799 into main Nov 18, 2026
2 checks passed
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.

2 participants