pyvista_cad.read_dxf

On this page

pyvista_cad.read_dxf#

read_dxf(path, /, *, clean=True, keep_text=False, expand_blocks=True, layout='modelspace', **_)[source]#

Read a DXF file as a pyvista.PolyData.

Parameters:
pathstr or os.PathLike

Path to a .dxf file (ASCII or binary, any AutoCAD version supported by ezdxf).

cleanbool, default: True

Run pyvista.PolyData.clean() on the result to merge coincident vertices and drop degenerate cells. DXF files almost always store coincident vertices per face, so cleaning is on by default.

keep_textbool, default: False

Include TEXT / MTEXT / ATTRIB entities by tessellating their bounding rectangles into faces; the text content is stored in a Text cell-data string array.

expand_blocksbool, default: True

Recursively expand INSERT block references into real geometry.

layoutstr, default: 'modelspace'

'modelspace', 'paperspace', or a specific layout name.

**_Any

Additional keyword arguments are accepted for forward compatibility with pyvista.read() and ignored here.

Returns:
pyvista.PolyData

Aggregated mesh containing every drawable entity. A Layer cell-data string array records the originating DXF layer; the same data is mirrored to cad.layer for forward compat.

Raises:
FileNotFoundError

If path does not exist.

pyvista_cad.CadReadError

If the file cannot be parsed as a DXF.

Parameters:
Return type:

PolyData

Examples

Read the bundled DXF plate fixture:

>>> import pyvista_cad
>>> from pyvista_cad import read_dxf
>>> mesh = read_dxf(pyvista_cad.examples.dxf_plate)
>>> type(mesh).__name__
'PolyData'
>>> str(mesh.field_data['cad.source_format'][0])
'dxf'