pyvista_cad.write_dxf#
- write_dxf(mesh, path, /, *, layer='0', layer_array='Layer', dxf_version='R2018', units=None, color_index=None, **_)[source]#
Write a
pyvista.PolyDataas a DXF file using ezdxf.- Parameters:
- meshpyvista.PolyData
Source mesh. Vertex cells become
POINT, line cells becomeLINE(2 points) orPOLYLINE(more), triangular and quadrilateral faces become3DFACE, and higher-degree polygons become DXFMESHentities.- pathstr or os.PathLike
Destination
.dxfpath.- layerstr, default:
'0' Default DXF layer when
layer_arrayis unset or missing.- layer_arraystr or None, default:
'Layer' Name of a cell-data array to use for per-cell layer assignment. When
None, every cell goes onlayer.- dxf_versionstr, default:
'R2018' ezdxf-supported version string.
- unitsstr or None, optional
Canonical unit string (
'mm','inch', …). When omitted,field_data['cad.units']is consulted and falls back to unitless.- color_indexint or None, optional
DXF color index (0-256) applied to every entity. When
None, DXF’s defaultBYLAYERcolor resolution is used.- **_Any
Additional keyword arguments are accepted for forward compatibility and ignored here.
- Returns:
- None
The file is written to
path.
- Raises:
- pyvista_cad.CadWriteError
If
meshis not apyvista.PolyDataor if writing fails on disk.
- Parameters:
- Return type:
None
Examples
Write a sphere to a DXF file in a temporary directory:
>>> import os >>> import tempfile >>> import pyvista as pv >>> from pyvista_cad import write_dxf >>> tmp = tempfile.mkdtemp() >>> out = os.path.join(tmp, 'sphere.dxf') >>> write_dxf(pv.Sphere(), out) >>> os.path.exists(out) True