Skip to main content

Intermediate representation (IR) for 2D CAD and DXF converters

Project description

cad2d-ir

cad2d-ir is an intermediate representation (IR) for 2D CAD data, plus converters between DXF and that IR.

The goal is to provide a stable, machine-friendly format for:

  • CAD ingestion pipelines
  • geometric post-processing
  • round-trip conversion workflows

Status

The project currently supports:

  • LINE, CIRCLE, ARC, LWPOLYLINE, TEXT
  • MTEXT, INSERT, HATCH
  • staged support for SPLINE, DIMENSION, and constraints

See ir_schema.json for the canonical schema.

Installation

With pip

pip install cad2d-ir

For development (uv)

uv sync
uv run pytest

CLI

# Validate IR JSON
cad2d-ir validate examples/ir/minimal.json

# DXF -> IR
cad2d-ir dxf2ir examples/dxf/simple_line.dxf -o /tmp/out.json --pretty

# IR -> DXF
cad2d-ir ir2dxf examples/ir/minimal.json -o /tmp/out.dxf

Warnings (for example when constraints cannot be represented in plain DXF) are printed to stderr.

Python API

from cad2d_ir import convert_dxf_text_to_ir, convert_ir_to_dxf_text

dxf_text = "0\nSECTION\n2\nENTITIES\n0\nLINE\n10\n0\n20\n0\n11\n1\n21\n1\n0\nENDSEC\n0\nEOF\n"
to_ir = convert_dxf_text_to_ir(dxf_text)
print(to_ir.document["entities"][0]["kind"])  # LINE

to_dxf = convert_ir_to_dxf_text(to_ir.document)
print(len(to_dxf.warnings))

Lower-level conversion functions (dxf_to_ir, ir_to_dxf) are also available.

Repository layout

src/cad2d_ir/
  api.py             # public high-level API
  cli.py             # CLI entrypoint
  schema.py          # schema loading + validation
  codecs/dxf.py      # DXF <-> IR conversion
  data/ir_schema.json
ir_schema.json       # canonical schema source
tests/
examples/
docs/

Compatibility and limitations

  • constraints are preserved in IR but omitted when exporting to DXF.
  • DIMENSION support is semantic/staged and may not preserve every CAD-system-specific detail.
  • HATCH currently focuses on polyline-style loops.

Development

uv run pytest -q
uv run cad2d-ir --help

See:

  • CONTRIBUTING.md
  • docs/API.md
  • docs/SCHEMA_NOTES.md

License

MIT (LICENSE)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cad2d_ir-0.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cad2d_ir-0.1.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file cad2d_ir-0.1.0.tar.gz.

File metadata

  • Download URL: cad2d_ir-0.1.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for cad2d_ir-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7b5f2441813dc0ed82dcb8880963c712a77707932181a2b0792450d4fd5b971
MD5 d4800fd87e843027243a3aea9bad8134
BLAKE2b-256 598bf3e3214c289bee4018dc41e555fd1ccd47ef8c359cbefa3c6e7770c8de98

See more details on using hashes here.

File details

Details for the file cad2d_ir-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cad2d_ir-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for cad2d_ir-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 119acdb33e698ad0f82a241f8c9b8d0f9b530d500cc9c65212c7a7ebffca01f8
MD5 47213006bc3abda1749df5d5d6d9b92e
BLAKE2b-256 6973ba51016545699a745bbb38c51db51e542d920602bdba1e940ed458f672e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page