Note
Go to the end to download the full example code.
PyVista -> TopoDS_Compound#
Send a tessellated pyvista.PolyData back into the OCCT world
as a faceted TopoDS_Compound. Useful when downstream OCCT-based
code expects shape objects rather than meshes, e.g. boolean
operations or further OCCT-native exports.
This example loads a real STEP part, the NIST AM Bench 2022 LPBF
bridge specimen (public domain, https://doi.org/10.18434/mds2-2607),
pushes it through to_topods, performs a boolean cut in OCCT
(the kind of operation that only works on a TopoDS shape), then
rounds it back to PyVista.
from OCP.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCP.gp import gp_Pnt
import pyvista as pv
import pyvista_cad
from pyvista_cad.examples import downloads
Load the real STEP part.
mesh = pyvista_cad.read_step(downloads.step_part_path()).combine().extract_surface()
mesh
/home/runner/work/pyvista-cad/pyvista-cad/examples/03_bridges/to_topods.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.
mesh = pyvista_cad.read_step(downloads.step_part_path()).combine().extract_surface()
Push to OCCT.
shape = pyvista_cad.to_topods(mesh)
type(shape).__name__
'TopoDS_Shape'
Boolean-cut against an OCCT primitive: an operation that lives in TopoDS-land, not available on a PyVista mesh. The box trims one end of the specimen.
'TopoDS_Shape'
Round-trip the cut compound back to PyVista.
back = pyvista_cad.from_topods(cut_result)
back
Render the post-cut part.
back['X (mm)'] = back.points[:, 0]
pl = pv.Plotter()
pl.cad.add(back, scalars='X (mm)', cmap='inferno')
pl.show()

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