Skip to main content

cad2d-ir

cad2d-ir is a typed intermediate representation and conversion toolkit for 2D CAD data.

日本語: 2D CAD の図面(JWW、SXF、DWG、DXF など)を 1 つの中間表現に読み込み、DXF に書き出す Python のライブラリです。説明はこのページの下にあります。

It provides:

  • a canonical JSON Schema for 2D CAD geometry and tables;
  • native DXF, DWG, DGN, DWF/DWFx, EDRW (eDrawings), EXB, HP-GL/PLT, ICD (iCAD SX), IDW, JWW, JWS, MI/BI, SXF, and vector PDF import paths;
  • DXF R12 (AC1009) and R2010 (AC1024) export;
  • structured import/export diagnostics;
  • deterministic IR-entity to DXF-handle correspondence.

Installation

pip install cad2d-ir
pip install "cad2d-ir[dwg]"
pip install "cad2d-ir[dgn]"
pip install "cad2d-ir[dwf]"
pip install "cad2d-ir[edrawings]"   # eDrawings drawings (.edrw); Linux x86_64, Windows, macOS arm64
# HP-GL: install local ezhpgl + cad2d-ir wheels until the first ezhpgl release
# then: pip install "cad2d-ir[hpgl]"
pip install "cad2d-ir[idw]"   # Python 3.11+; see the IDW license notice below
pip install "cad2d-ir[jww]"
pip install "cad2d-ir[mi]"
pip install "cad2d-ir[pdf]"   # vector PDF (pypdfium2)
pip install "cad2d-ir[sxf]"
pip install "cad2d-ir[all]"

Python 3.10 or newer is required. Format adapters are optional extras.

The DXF writer and the entity conversion of the JWW importer are written in Rust: cad2d-ir installs cad2d-ir-native of the same version with it. There are wheels for Linux (x86_64 and aarch64, glibc), Windows (x86_64) and macOS (universal2), one for every Python from 3.10; on another platform pip builds the source distribution, which needs a Rust toolchain. See native/.

IDW license notice: IDW support uses inventor-kit, which is offered under PolyForm Noncommercial 1.0.0 with separate commercial licenses. Before using IDW in commercial workflows, including internal business use, review the IDW licensing terms.

pip install cad2d-ir and pip install "cad2d-ir[all]" do not install inventor-kit; install [idw] explicitly when needed. The development command uv sync --all-extras below includes [idw] and installs inventor-kit.

HP-GL uses ezhpgl through the optional [hpgl] extra. See HP-GL conversion for local wheel installation, paper-space mapping, page selection and loss reporting.

For development, the current lock requires an adjacent ../ezhpgl checkout until its first registry release. Registry CI validation follows publication:

uv sync
uv sync --all-extras
uv run python -m pytest

Supported data

IR entities include LINE, CIRCLE, ARC, POINT, ELLIPSE, LWPOLYLINE, SPLINE, TEXT, MTEXT, INSERT, HATCH, DIMENSION, and IMAGE. Layer, linetype, text-style, dimension-style, and block tables are represented by the schema. entities is model space; the paper-space sheets of a DXF or DWG drawing, with their viewports onto model space, are kept apart in layouts.

Import adapters:

Format Path Dependency
DXF built-in parser core
DWG native ezdwg model cad2d-ir[dwg]
DGN V7 2D / V8 native ezdgn models cad2d-ir[dgn]
DWF/DWFx 2D normalized ezdwf sheet model cad2d-ir[dwf]
EDRW (eDrawings drawing sheets) HOOPS segment tree from edrawings-kit cad2d-ir[edrawings]
EXB (CAXA CAD / 电子图板) stored-entity model from ezexb cad2d-ir[exb]
HP-GL / HP-GL/2 / bounded PCL/PJL Rust plot model from ezhpgl cad2d-ir[hpgl]
ICD (iCAD SX 2D drawing area) saved views and entities from icadkit cad2d-ir[icad]
IDW (Autodesk Inventor drawing) saved-display model from inventor-kit cad2d-ir[idw]
JWW native ezjww model cad2d-ir[jww]
JWS (Jw_cad registered symbol) native ezjww model (0.7 or later) cad2d-ir[jww]
MI / gzip-wrapped BI native ezmi2d document model cad2d-ir[mi]
PDF (vector plot) PDFium page objects via pypdfium2; arcs, linetypes, layers, text and plot scale recovered cad2d-ir[pdf]
SXF SFC/P21 backend-neutral ezsxf drawing cad2d-ir[sxf]

Native adapters preserve source semantics and provenance rather than flattening through an intermediate DXF.

CLI

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

# DXF -> IR with BOM/codepage/UTF-8/CP932 detection
cad2d-ir dxf2ir drawing.dxf -o drawing.json --pretty
cad2d-ir dxf2ir drawing.dxf --encoding cp932 -o drawing.json

# Auto-detected DXF/DWG/DGN/DWF/DWFx/EDRW/EXB/HP-GL/ICD/IDW/JWW/JWS/MI/BI/PDF/SFC/P21 -> IR
cad2d-ir import drawing.JWW -o drawing.json --pretty
cad2d-ir import drawing.dwg -o drawing.json --pretty
cad2d-ir import drawing.dgn -o drawing.json --pretty
cad2d-ir import drawing.dwfx -o drawing.json --pretty
cad2d-ir import drawing.edrw -o drawing.json --pretty
cad2d-ir import drawing.exb -o drawing.json --pretty
cad2d-ir import drawing.idw -o drawing.json --pretty
cad2d-ir import drawing.mi -o drawing.json --pretty
cad2d-ir import plot.pdf -o plot.json --pretty
cad2d-ir import drawing.p21 -o drawing.json --pretty

# HP-GL -> all-page IR, or one explicit paper-space DXF page
cad2d-ir import drawing.plt -o drawing.ir.json --pretty
cad2d-ir hpgl2dxf drawing.plt --page 1 -o page1.dxf --report page1-report.json
# Status 1 means a partial/approximate result was written; inspect the report.

# IR -> R2010 or R12 DXF
cad2d-ir ir2dxf drawing.json --target-version AC1024 -o drawing-r2010.dxf
cad2d-ir ir2dxf drawing.json --target-version AC1009 \
  --curve-segments 128 -o drawing-r12.dxf

Python API

from cad2d_ir import convert_file_to_ir, convert_ir_to_dxf_text

imported = convert_file_to_ir("drawing.dxf", strict=False)
print(imported.statistics["encoding"])
for diagnostic in imported.diagnostics:
    print(diagnostic.code, diagnostic.as_dict())

exported = convert_ir_to_dxf_text(
    imported.document,
    target_version="AC1024",
    generic_dimensions="explode",
)
for entry in exported.entity_map:
    print(entry["ir_id"], entry["handle"], entry["dxf_type"])

R2010 output assigns deterministic handles and emits $HANDSEED. Re-importing the DXF records each handle in entity.source.id. R12 omits handles and retains deterministic index values in the entity map.

convert_file_to_ir("model.dwg", keep_3d=True) additionally returns the geometry DWG/DXF sources had before XY projection (3D polylines, faces, block placements, counts of unreadable solids) in ImportResult.model3d; the IR itself stays two-dimensional. See docs/IMPORTERS.md, "3D side channel".

Export behavior

  • TABLES contains LAYER, LTYPE, and STYLE records from IR tables; R2010 output also has the other symbol tables, the block records, the owners and the named object dictionary AutoCAD and ODA need to read DXF R2000+.
  • GENERIC dimensions expand to their preserved visual primitives by default.
  • R2010 line weights (group 370) are written as the nearest of the line weights DXF has (0.17 mm becomes 0.18 mm); readers take any other value for "by layer".
  • Temporary (construction) points, POINT entities with temporary: true, are not written: DXF has no points that are shown and left out of a plot.
  • R12 text is stored in the Windows code page its characters ask for, named in $DWGCODEPAGE (ANSI_932 for Japanese and plain ASCII drawings, ANSI_936 for simplified Chinese, and so on); LWPOLYLINE becomes POLYLINE/VERTEX, MTEXT becomes TEXT, ELLIPSE/SPLINE become sampled polylines, and HATCH becomes boundary polylines.
  • Every skip, approximation, explosion, and normalization is represented by an ExportDiagnostic.
  • The same document and options produce byte-identical DXF and entity-map output within a package minor version.

Compatibility boundaries

  • constraints are IR-only and are diagnosed when omitted from DXF.
  • A complete affine INSERT.transform cannot be represented by plain DXF INSERT and is diagnosed when omitted.
  • R12 has no true-color, lineweight, or $INSUNITS equivalent with the same semantics; downgrade diagnostics disclose those losses.
  • HATCH support focuses on polyline-style loops.
  • Ellipse start/end parameters are radians independently of header.angle_unit.
  • DGN import covers V7 2D and native V8 documents. V7 text encoding auto-detection probes ASCII, CP932, then Latin-1 at file scope; V8 text arrives already decoded per element. ezdgn rejects V7 3D; V8 3D models and multi-model files are reduced to one projected model with explicit loss diagnostics, and V8 shared-cell definitions, fills, color tables, and spline knots are not decoded yet.
  • DWF/DWFx import preserves sheet identity in metadata while placing supported 2D entities and markups in one IR modelspace. Raster payloads and complex brush semantics remain source metadata/diagnostics rather than invented IR geometry.
  • IDW import consumes the saved sheet display returned by inventor_kit.read_drawing_file (lines, curves, filled triangles, text and image placements as Inventor stored them). It does not open referenced IPT/IAM files or regenerate views, so drawing views that Inventor saved only as raster caches (for example every view in 2027-era files) have no vector geometry in the IR; their placements are kept in source.metadata.idw and disclosed by IDW_VIEW_RASTER_ONLY / IDW_IMAGE_NOT_IN_IR. Coordinates are sheet paper space scaled from Inventor's internal centimetres to millimetres (IDW_UNITS_ASSUMED_CM); multiple sheets are tiled along +X. Supported segment majors follow inventor-kit (23, 24, 26, 28, 29, 31 in 0.6.0); other profiles raise ImporterError("unsupported IDW profile ..."). inventor-kit needs Python 3.11+; see the IDW licensing terms. inventor-kit 0.10 installs no geometry kernel by default (CadQuery/OCCT come only with its own cadquery / occt extras for IPT/IAM geometry), so cad2d-ir[idw] needs no dependency override.
  • MI import consumes ezmi2d>=0.2,<0.3 directly. Part definitions and shared occurrences become IR blocks and INSERTs; source radians are normalized to IR degrees. .bi dispatch covers the gzip-wrapped MI container verified by ezmi2d, not every historical Drafting/ME10 BI compression variant.

See:

Repository layout

src/cad2d_ir/
  api.py
  cli.py
  diagnostics.py
  schema.py
  codecs/dxf.py          the DXF reader; the writer is in native/
  importers/
  data/ir_schema.json
native/                  cad2d-ir-native (Rust): the DXF writer and the
                         entity conversion of the JWW importer
ir_schema.json
tests/
examples/
docs/

日本語

cad2d-ir は、2D CAD の図面を 1 つの型付きの中間表現(IR。JSON Schema つき)に読み込み、DXF に書き出す Python のライブラリです。形式ごとの読み取りは、追加のパッケージ(extras)で入れます。DXF の書き出しと JWW の要素の変換は Rust で書いてあり、pip install cad2d-ir で cad2d-ir-native(Linux・Windows・macOS の wheel)が一緒に入ります。

  • 読める形式: DXF、DWG、DGN、DWF / DWFx、EDRW(eDrawings)、EXB(CAXA)、HP-GL / PLT、ICD(iCAD SX)、IDW(Inventor)、JWW・JWS(Jw_cad)、MI / BI(ME10)、SXF(SFC・P21)、ベクター PDF
  • 書き出し: DXF R12(AC1009)と R2010(AC1024)
  • 読み取りと書き出しで落ちた情報は、診断として構造化して返します
pip install "cad2d-ir[jww]"   # Jw_cad
pip install "cad2d-ir[sxf]"   # SFC・P21
pip install "cad2d-ir[dwg]"   # DWG
from pathlib import Path

from cad2d_ir import convert_file_to_ir, convert_ir_to_dxf_text

imported = convert_file_to_ir("drawing.jww", strict=False)  # 形式は中身から判別する
for diagnostic in imported.diagnostics:
    print(diagnostic.code, diagnostic.as_dict())

exported = convert_ir_to_dxf_text(imported.document, target_version="AC1024")
Path("drawing.dxf").write_text(exported.dxf_text, encoding="utf-8")

IDW(inventor-kit)と ICD(icadkit)の読み取りは、PolyForm Noncommercial のパッケージを使います。商用で使う前に、下の License とそれぞれのパッケージのライセンスを確認してください。

関連するライブラリ: 形式ごとの読み書きは ezjww(Jw_cad)、ezsxf(SXF)、ezdwg(DWG)。インストールせずにブラウザで図面を開く・変換するなら zumen-gate が使えます。

License

cad2d-ir itself is licensed under MIT (LICENSE), including its IDW adapter code. Optional parser dependencies retain their own licenses.

IDW licensing (inventor-kit)

IDW support depends on inventor-kit, which is offered under PolyForm Noncommercial 1.0.0 with separate commercial licenses from UnRobotics Inc. The MIT license for cad2d-ir does not grant additional rights to use or redistribute inventor-kit.

  • Use permitted by the PolyForm terms does not require a commercial agreement.
  • Use outside those permissions, including commercial internal business use and commercial product integration, requires a separate written commercial agreement with UnRobotics Inc. See the upstream commercial licensing guide and contact form.
  • If you redistribute inventor-kit with your application, comply with its distribution terms and preserve the applicable license texts and notices.

These additional conditions concern the inventor-kit dependency used for IDW support. Workflows using only other formats do not require inventor-kit; their respective dependency licenses still apply. Refer to the upstream license notice for the full scope, including earlier MIT material and third-party components.

Metadata

Release files for cad2d-ir 0.18.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cad2d-ir 0.18.0
File Size Uploaded Provenance Actions
cad2d_ir-0.18.0.tar.gz 307.7 kB Without provenance Details for cad2d_ir-0.18.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cad2d-ir 0.18.0
File Interpreter ABI Platform Actions
cad2d_ir-0.18.0-py3-none-any.whl Python 3 none any Details for cad2d_ir-0.18.0-py3-none-any.whl

Total release size: 634.6 kB

Release files / cad2d_ir-0.18.0.tar.gz

Download URL cad2d_ir-0.18.0.tar.gz
Size 307.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7f47c5a54b374bded0f5b5ea47566c53f43b6590a2cb7d97c58e721c076edb1d
BLAKE2b-256 checksum
How to use checksums
8fae50f707a03eb8d1d690db78800eec2c014118a8e494ba51b9d140a237936e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cad2d_ir-0.18.0-py3-none-any.whl

Download URL cad2d_ir-0.18.0-py3-none-any.whl
Size 326.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a635f76372533c16395c09176842ed22b43bb9c01462618a4e64a4ce55048a7a
BLAKE2b-256 checksum
How to use checksums
519844f1a2951146817fd133ab57f1556f708c8fd6919e54c1d694ca70f22785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cad2d-ir 0.18.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.18.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page