pyvista_cad.write_step#
- write_step(dataset, path, /, *, write_assembly=True, **_)[source]#
Write a
pyvista.PolyDataorpyvista.MultiBlockas STEP.Each input triangle is converted to a planar face; the faces are sewn with
BRepBuilderAPI_Sewingso a watertight mesh becomes a single closed shell, which is promoted to aTopoDS_Solidwhen closed. The output is a faceted STEP, not a B-rep reconstruction: analytic surface information is not recovered.When
datasetis apyvista.MultiBlockandwrite_assemblyisTrue(the default), a labelled OCAF assembly is emitted – one STEP product per block, the block key used as the component name, and nested MultiBlocks written as nested sub-assemblies (recursion is unbounded). A per-blockfield_data['cad.transform'](raveled row-major 4x4) is applied as the component placement. The placement must be affine: only the top three rows are read into the OCCTgp_Trsf. The projective bottom row is assumed to be[0, 0, 0, 1]and is silently dropped, so a non-affine 4x4 does not round-trip. Whenwrite_assemblyisFalseordatasetis a singlepyvista.PolyData, the geometry is collapsed into one flatTopoDS_Compound.Round-trip metadata: a
read_step()of the written file withmerge=Falserecovers per-partcad.color,cad.labelandcad.transform. Withmerge=Truethe parts are flattened bypyvista.MultiBlock.combine(), which keeps only the rootcad.source_format/cad.units/cad.reader/cad.backend; per-partcad.color,cad.labelandcad.transformdo not survive the merge.Chordal-deviation bound: the faceted STEP is the input triangulation, vertex-for-vertex, except that
polydata_to_topods()sews faces with a tolerance ofmax(diag * 1e-6, 1e-9)(diag= bounding-box diagonal), so vertices closer together thandiag * 1e-6may be welded. Apart from that welding, deviation from the original analytic surface stays bounded by thelinear_deflectionused when that surface was tessellated intodataset(seeread_step()); this writer introduces no further geometric error.- Parameters:
- datasetpyvista.PolyData or pyvista.MultiBlock
Source dataset.
- pathstr or os.PathLike
Destination
.stepor.stppath.- write_assemblybool, default: True
Emit a labelled OCAF assembly for MultiBlock inputs. When
False, MultiBlock inputs are flattened into one compound.- **_Any
Forward-compat keyword arguments are accepted and ignored.
- Raises:
- pyvista_cad.CadWriteError
If
datasetis an unsupported type, if no geometry is found, or if one or more blocks cannot be faceted (every dropped block is named in the message; no block is silently dropped).- pyvista_cad.OptionalDependencyError
If OCP is not installed.
- Parameters:
- Return type:
None
Examples
>>> import tempfile, pathlib >>> import pyvista as pv >>> import pyvista_cad # noqa: F401 >>> asm = pv.MultiBlock() >>> asm['Base'] = pv.Box() >>> asm['Pin'] = pv.Sphere() >>> with tempfile.TemporaryDirectory() as d: ... out = pathlib.Path(d) / 'asm.step' ... pyvista_cad.write_step(asm, out) ... out.exists() True