A lightweight, pure-Python command-line tool for converting 3D DXF files to industry-standard CAD formats (STL, STEP, IGES). Ideal for CAD workflows, 3D printing preparation, and multi-tool design ecosystems.
| Entity Type | Description | Handling |
|---|---|---|
| 3DFACE | Triangle / quad faces (most common) | Quads preserved as 4-sided faces; degenerate quads → triangles |
| MESH | DXF 2010+ subdivision meshes | Tessellated to triangles |
| POLYLINE (PFACE) | Polyface mesh (closed edge loops) | Extracted and tessellated |
| POLYLINE (POLYMESH) | Parametric M×N surface grids | Converted to regular triangle mesh |
| INSERT | Block references | Recursively expanded to extract nested geometry |
- 3DSOLID, BODY, REGION — These store geometry as embedded ACIS/SAT binary blobs. To include them, export directly to STEP/STL from your source CAD application.
- 2D geometry (LINE, CIRCLE, SPLINE) — Ignored silently
- Format: Binary triangle mesh
- Best for: 3D printing, mesh visualization, FEA solvers
- Attributes: Pure geometry; no topology or features
- File size: Compact (typically smallest of the three formats)
- Standard: AP214 (
AUTOMOTIVE_DESIGN) - Structure:
SHELL_BASED_SURFACE_MODELcontainingADVANCED_FACEentities - Best for: Professional CAD workflows, Creo, SolidWorks, FreeCAD, NX
- Geometry precision: 1E-07 millimeters (per ISO 10303)
- Version: 5.3
- Geometry: Entity 144 (Trimmed Parametric Surfaces) with Entity 102 (Composite Curves)
Input DXF
↓
[1] Parse modelspace with ezdxf
• Expand INSERT blocks recursively
• Extract 3DFACE, MESH, POLYLINE entities
• Collect vertices and face indices
↓
[2] Geometry Extraction
• 3DFACE → preserve quads, detect degenerate faces
• MESH → tessellate to triangles
• POLYLINE → expand Polyface/Polymesh
↓
[3] Mesh Cleaning (optional)
• Verify vertex normals
• Skip zero-area faces
• Merge duplicate vertices (if --aggressive flag used)
↓
[4] Format-Specific Export
• STL: Binary triangle mesh
• STEP: AP214 shell with ADVANCED_FACE topology
• IGES: Entity 144 trimmed parametric surfaces
↓
Output CAD-ready file(s)
When a DXF file contains quad faces (4-sided polygons), they are preserved as 4-sided ADVANCED_FACE entities in STEP and IGES output:
| Format | Quads | Result |
|---|---|---|
| STL | Split to 2 triangles (STL limitation) | 15,460 triangles from 9,704 tri + 2,878 quad |
| STEP | Preserved as 4-sided faces | 11,938 faces (no unnecessary diagonals) |
| IGES | Preserved as 4-sided surfaces | 11,938 trimmed surfaces (clean topology) |
Example: A rectangular roof opening (quad) exports as a single selectable 4-sided face in Creo instead of 2 triangles with a diagonal split.
- Python 3.8 or later — Download here
- Windows, macOS, or Linux — Platform-independent
pip install ezdxf numpy-stl numpyWhat each package does:
ezdxf— Parses DXF files and extracts 3D geometrynumpy-stl— Writes binary STL files efficientlynumpy— Numerical operations (normal vectors, mesh math)
STEP and IGES export require no additional packages — writers are implemented in pure Python.
git clone <repository-url>
cd dxf_converterOr place dxf_converter.py in your project directory.
python dxf_converter.py <input.dxf> [--format FORMAT] [--output PATH] [--aggressive]| Argument | Type | Default | Description |
|---|---|---|---|
input |
Path | required | Path to input .dxf file |
--format |
str | iges |
Output format(s): stl, step, iges, or all |
--output |
Path | auto | Output base path (no extension). If omitted, uses input filename |
--aggressive |
flag | off | Apply aggressive mesh optimization (slower, better for Creo) |
python dxf_converter.py my_roof.dxf
# Output: my_roof.igs (24.2 MB)python dxf_converter.py my_roof.dxf --format step
# Output: my_roof.stp (16.8 MB)python dxf_converter.py my_roof.dxf --format stl
# Output: my_roof.stl (773 KB)python dxf_converter.py my_roof.dxf --format all
# Output: my_roof.igs, my_roof.stp, my_roof.stlpython dxf_converter.py my_roof.dxf --format all --output /exports/roof_v2
# Output: /exports/roof_v2.igs, /exports/roof_v2.stp, /exports/roof_v2.stlpython dxf_converter.py my_roof.dxf --format step --aggressive
# Simplifies mesh + merges vertices before exportCause: DXF contains only 2D entities (LINE, CIRCLE, SPLINE) or ACIS solids.
Solution:
- Verify the source DXF contains 3D mesh entities (3DFACE, MESH, POLYLINE)
- In your source CAD tool, export 3D surfaces/faces explicitly (not edge wireframes)
- For ACIS solids, export directly to STEP/STL from your CAD program
Cause: Required package not installed.
Solution:
pip install ezdxf numpy-stl numpyExpected behavior: STEP and IGES store one entity per face + topology metadata.
- 50,000 triangles → ~40+ MB STEP file (normal)
- 50,000 triangles → ~1-2 MB STL file (compact mesh-only format)
Why the difference? STEP/IGES include edge loops, normal vectors, surface definitions, and product metadata for CAD feature work. STL is pure geometry.
Meaning: Zero-area polygons (duplicate vertices, collinear points) detected and skipped.
Resolution: Automatic. These faces contribute nothing to the mesh and are safely filtered.
Possible cause: Inverted face normals or non-manifold geometry in source DXF.
Solution:
- Try importing as a reference model (visualization only)
- Use the
--aggressiveflag to clean the mesh:python dxf_converter.py model.dxf --format step --aggressive
- In Creo: Create a new part → Insert DXF as reference → Re-surface
Cause: Using older version of the converter that splits all quads.
Solution: Ensure dxf_converter.py is up to date. The current version preserves quads as 4-sided faces in STEP/IGES output.
When enabled, the converter applies vertex merging for triangle-only meshes:
python dxf_converter.py model.dxf --format step --aggressiveEffects:
- Merges vertices within tolerance (1e-6 mm)
- Removes duplicate faces
- Reduces file size slightly
⚠️ Note: Only applied when no quads are present (quads are always preserved)
Useful for organizing exports into subdirectories:
python dxf_converter.py roof_concept.dxf --format all --output ./exports/roof_v2
# Creates: ./exports/roof_v2.igs, ./exports/roof_v2.stp, ./exports/roof_v2.stl| Operation | Time | Notes |
|---|---|---|
| Parse 22K-vertex DXF | ~500 ms | Via ezdxf |
| Extract geometry | ~100 ms | Tessellation + indexing |
| Write STL | ~50 ms | Binary format, compact |
| Write STEP | ~2 s | Complex topology encoding |
| Write IGES | ~3 s | Verbose entity structure |
| Total (all formats) | ~6 s | For typical roof concept model |
Scalability: Tested up to 100K+ vertices / 50K+ faces on standard hardware.
- Standard: ISO 10303-21, Part 214 (Automotive Design)
- Topology: Each face →
ADVANCED_FACEonPLANEsurface inOPEN_SHELL - Precision: 1E-07 mm uncertainty measure
- Units: Meters (SI)
- Version: 5.3
- Geometry: Entity 144 (Trimmed Parametric Surface)
- Boundaries: Entity 102 (Composite Curve) + Entity 110 (Line) edges
- Surface: Entity 108 (Plane)
- Format: Binary (compact, no ASCII overhead)
- Tessellation: All faces converted to triangles (STL limitation)
- Normals: Computed per-triangle from vertex cross-product
| Issue | Workaround |
|---|---|
| DXF ACIS solids not supported | Export directly to STEP/STL from source CAD tool |
| STL format requires triangle tessellation | Use STEP/IGES for quad preservation |
| Very large files (1M+ faces) may be slow | Split DXF into multiple files before conversion |
| Some legacy IGES viewers struggle with complex topology | Use STEP format instead; better supported |
MIT License — Free for commercial and personal use.
| Version | Changes |
|---|---|
| 1.2 (Current) | Cylinder end cap generation — POLYMESH cylinders now generate fan-triangulated end caps for closed geometry; new --normal-tolerance and --keep-degenerate flags for fine-tuned face filtering |
| 1.1 | Quad preservation in STEP/IGES; improved face topology |
| 1.0 | Initial release; STEP/IGES/STL export |
Questions? See Troubleshooting or review the Usage section.