Write a BREP file

Write a BREP file#

Serialize a tessellated pyvista.PolyData as a faceted TopoDS_Compound in OpenCASCADE’s native BREP format. BREP is the canonical handoff to any OCCT-aware tool (FreeCAD, build123d, cadquery).

This example loads a real STEP fixture, the NIST AM Bench 2022 recoater-guide part (public domain, https://doi.org/10.18434/mds2-2607), writes it out to BREP, and reads it back, confirming the round-trip preserves geometry that downstream OCCT code can consume.

from pathlib import Path
import tempfile

import pyvista as pv

import pyvista_cad
from pyvista_cad.examples import downloads

Load the real part and write it to BREP.

/home/runner/work/pyvista-cad/pyvista-cad/examples/02_writers/write_brep.py:30: PyVistaFutureWarning: The default value of `algorithm` for the filter
`UnstructuredGrid.extract_surface` will change in the future. It currently defaults to
`'dataset_surface'`, but will change to `None`. Explicitly set the `algorithm` keyword to
silence this warning.
  src = pyvista_cad.read_step(downloads.step_recoater_path()).combine().extract_surface()

Read back and verify the tessellation reproduces the source.

poly = pyvista_cad.read_brep(path, linear_deflection=0.1)
poly
PolyData (0x7f6fa8bcb3a0)
  N Cells:    416
  N Points:   1248
  N Strips:   0
  X Bounds:   -4.500e+01, 4.500e+01
  Y Bounds:   0.000e+00, 1.250e+01
  Z Bounds:   -2.490e+00, 2.490e+00
  N Arrays:   3


Render colored by Z.

poly['Z'] = poly.points[:, 2]

pl = pv.Plotter()
pl.cad.add(poly, scalars='Z', cmap='cividis')
pl.show()
write brep

Total running time of the script: (0 minutes 2.023 seconds)