Skip to content

Fix DXF export rejected by eDrawings/AutoCAD viewers - #13

Merged
YurMil merged 1 commit into
mainfrom
fix/dxf-r12-compatibility
Jul 20, 2026
Merged

Fix DXF export rejected by eDrawings/AutoCAD viewers#13
YurMil merged 1 commit into
mainfrom
fix/dxf-r12-compatibility

Conversation

@YurMil

@YurMil YurMil commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Exported DXF files failed to open in strict viewers (eDrawings, AutoCAD viewer) with "Error reading file".

Cause: the header declared $ACADVER = AC1015 (AutoCAD 2000) while the file body was a minimal HEADER/TABLES/ENTITIES structure. AC1015 makes CLASSES, BLOCKS and OBJECTS sections, the full table set (VPORT/LTYPE/STYLE/APPID/DIMSTYLE/BLOCK_RECORD), and per-entity handles mandatory — strict parsers validate that and reject the file. Permissive viewers ignored it, which is why the bug went unnoticed.

Fix:

  • Declare DXF R12 (AC1009) — no such requirements, universally readable, fully sufficient for CIRCLE/LINE geometry
  • Define the CONTINUOUS linetype in an LTYPE table before the layers that reference it
  • $MEASUREMENT = 1 marks the drawing as metric (replaces the AC1015-only $INSUNITS)
  • 5 regression tests: version declaration, linetype-before-layers ordering, layer declarations, balanced SECTION/ENDSEC + EOF, entity counts

Verified: 63 tests pass (58 existing + 5 new), build green. Merging deploys the fixed bundle to cadautoscript.com.

🤖 Generated with Claude Code

…UOUS linetype

The file claimed AC1015 (AutoCAD 2000) while emitting only a minimal
HEADER/TABLES/ENTITIES structure; AC1015 makes CLASSES, BLOCKS, OBJECTS,
the full table set, and per-entity handles mandatory, so eDrawings and
AutoCAD viewers rejected the export with 'Error reading file'. R12
(AC1009) has no such requirements. Also defines the CONTINUOUS linetype
the layer table references, and adds regression tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the DXF exporter to target DXF R12 (AC1009) instead of AC1015, which improves compatibility with strict CAD viewers, and ensures the CONTINUOUS linetype is defined before layers reference it. It also introduces a new test suite for the exporter. The review feedback suggests two important improvements to the test file: avoiding unsafe type assertions (using 'as unknown as') to maintain TypeScript's type safety, and moving the DXF generation logic from the root of the 'describe' block into a 'beforeAll' hook to prevent potential failures during the test registration phase.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +5 to +11
const params = {
boardDiameter: 150,
tubeDiameter: 25,
partitionWidth: 10,
partitionOrientation: 'horizontal',
passCount: 2,
} as unknown as GeneratorParams;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using as unknown as GeneratorParams bypasses TypeScript's type safety guarantees. If buildTubeSheetDxf or other helper functions are updated in the future to require additional properties from GeneratorParams, this test will compile successfully but fail at runtime with NaN or undefined errors.

Instead, define a complete, type-safe GeneratorParams object with default values for the missing properties.

const params: GeneratorParams = {
  boardDiameter: 150,
  thickness: 10,
  tubeDiameter: 25,
  tubeLength: 1000,
  tubeLayout: 'square',
  tubePitch: 30,
  edgeMargin: 10,
  topCutoffChord: 0,
  bottomCutoffChord: 0,
  partitionWidth: 10,
  partitionOrientation: 'horizontal',
  passCount: 2,
};

Comment on lines +18 to +20
describe('buildTubeSheetDxf', () => {
const dxf = buildTubeSheetDxf(params, coords);
const lines = dxf.split('\n');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Executing code directly inside the describe block (outside of it, beforeEach, or beforeAll) runs during the test suite registration phase rather than the execution phase. If buildTubeSheetDxf throws an error, the entire test suite will fail to load, which can break test runners and produce confusing stack traces.

Move the DXF generation logic into a beforeAll block. Remember to also import beforeAll from 'vitest' on line 1.

describe('buildTubeSheetDxf', () => {
  let dxf: string;
  let lines: string[];

  beforeAll(() => {
    dxf = buildTubeSheetDxf(params, coords);
    lines = dxf.split('\n');
  });

@YurMil
YurMil merged commit 34b1f4f into main Jul 20, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 427c9ca232

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// $MEASUREMENT = 1 marks the drawing as metric (millimetres).
const buildHeader = () =>
['0', 'SECTION', '2', 'HEADER', '9', '$ACADVER', '1', 'AC1015', '9', '$INSUNITS', '70', '4', '0', 'ENDSEC'].join(
['0', 'SECTION', '2', 'HEADER', '9', '$ACADVER', '1', 'AC1009', '9', '$MEASUREMENT', '70', '1', '0', 'ENDSEC'].join(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve explicit millimeter units

When a user imports the exported DXF into a CAD/CAM workflow that infers scale from header units, this swaps the previous $INSUNITS=4 millimeter declaration for $MEASUREMENT=1; $MEASUREMENT only selects metric-vs-imperial linetype/hatch defaults and is independent of the modelspace unit, while $INSUNITS is what identifies millimeters (see https://ezdxf.readthedocs.io/en/stable/concepts/units.html). Because all UI inputs and filenames are in mm, these R12 files now become unitless/ambiguous and can be interpreted at the host drawing's default scale; if AC1009 is required for compatibility, we need another explicit unit strategy or a valid newer DXF path rather than dropping the millimeter declaration.

Useful? React with 👍 / 👎.

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.

1 participant