pyvista_cad.write_dxf

On this page

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.PolyData as a DXF file using ezdxf.

Parameters:
meshpyvista.PolyData

Source mesh. Vertex cells become POINT, line cells become LINE (2 points) or POLYLINE (more), triangular and quadrilateral faces become 3DFACE, and higher-degree polygons become DXF MESH entities.

pathstr or os.PathLike

Destination .dxf path.

layerstr, default: '0'

Default DXF layer when layer_array is 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 on layer.

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 default BYLAYER color 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 mesh is not a pyvista.PolyData or 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