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,TEXTMTEXT,INSERT,HATCH- staged support for
SPLINE,DIMENSION, andconstraints
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
constraintsare preserved in IR but omitted when exporting to DXF.DIMENSIONsupport is semantic/staged and may not preserve every CAD-system-specific detail.HATCHcurrently focuses on polyline-style loops.
Development
uv run pytest -q
uv run cad2d-ir --help
See:
CONTRIBUTING.mddocs/API.mddocs/SCHEMA_NOTES.md
License
MIT (LICENSE)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7b5f2441813dc0ed82dcb8880963c712a77707932181a2b0792450d4fd5b971
|
|
| MD5 |
d4800fd87e843027243a3aea9bad8134
|
|
| BLAKE2b-256 |
598bf3e3214c289bee4018dc41e555fd1ccd47ef8c359cbefa3c6e7770c8de98
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
119acdb33e698ad0f82a241f8c9b8d0f9b530d500cc9c65212c7a7ebffca01f8
|
|
| MD5 |
47213006bc3abda1749df5d5d6d9b92e
|
|
| BLAKE2b-256 |
6973ba51016545699a745bbb38c51db51e542d920602bdba1e940ed458f672e2
|