Inspect a STEP assembly

Inspect a STEP assembly#

A STEP file with multiple parts arrives as a pyvista.MultiBlock. Per-part labels and colors are attached as cad.label / cad.color field data. Use .cad.find and .cad.walk to navigate the tree.

This example loads a real multi-part STEP assembly, the NIST AM Bench 2022 build-plate layout (public domain, https://doi.org/10.18434/mds2-2607): a tapped substrate plate, four bridge specimens, and two recoater guides. It walks the metadata you can pull off any STEP assembly that lands on your desk.

import pandas as pd
import pyvista as pv

import pyvista_cad
from pyvista_cad.examples import downloads

Read the real assembly.

MultiBlock (0x7f6fa89aa920)
  N Blocks:   7
  X Bounds:   4.096e+01, 1.426e+02
  Y Bounds:   -1.994e+01, 8.166e+01
  Z Bounds:   -1.243e-15, 2.203e+01


Walk the tree. Each block carries its OCCT label and an optional color tuple.

rows = []
for path, block in mb.cad.walk():
    color = block.field_data.get('cad.color', None)
    rows.append(
        {
            'path': str(path),
            'label': block.field_data.get('cad.label', [b''])[0],
            'color': [round(float(c), 3) for c in color]
            if color is not None and len(color)
            else None,
            'cells': block.n_cells,
        }
    )
pd.DataFrame(rows)
path label color cells
0 AMMT_4x4x0_375_Substrate_Tapped AMMT_4x4x0_375_Substrate_Tapped [0.591, 0.638, 0.855, 1.0] 444
1 AMB2022-01-AMMT-PartCAD AMB2022-01-AMMT-PartCAD [0.527, 0.527, 0.527, 1.0] 436
2 AMB2022-01-AMMT-PartCAD AMB2022-01-AMMT-PartCAD [0.527, 0.527, 0.527, 1.0] 436
3 AMB2022-01-AMMT-PartCAD AMB2022-01-AMMT-PartCAD [0.527, 0.527, 0.527, 1.0] 436
4 AMB2022-01-AMMT-PartCAD AMB2022-01-AMMT-PartCAD [0.527, 0.527, 0.527, 1.0] 436
5 AMB2022-01-AMMT-RecoaterGuideCAD AMB2022-01-AMMT-RecoaterGuideCAD [0.591, 0.638, 0.855, 1.0] 416
6 AMB2022-01-AMMT-RecoaterGuideCAD AMB2022-01-AMMT-RecoaterGuideCAD [0.591, 0.638, 0.855, 1.0] 416


Source format and units round-trip on the container.

pd.DataFrame(
    {
        'source_format': [mb.field_data.get('cad.source_format', [b''])[0]],
        'units': [mb.field_data.get('cad.units', [b''])[0]],
    }
)
source_format units
0 step mm


Flatten: collapse arbitrary nesting to a single level.

list(mb.cad.flatten().keys())
['AMMT_4x4x0_375_Substrate_Tapped', 'AMB2022-01-AMMT-PartCAD', 'AMB2022-01-AMMT-PartCAD', 'AMB2022-01-AMMT-PartCAD', 'AMB2022-01-AMMT-PartCAD', 'AMB2022-01-AMMT-RecoaterGuideCAD', 'AMB2022-01-AMMT-RecoaterGuideCAD']

Render colored by Z.

for _, part in mb.cad.walk():
    part['Z'] = part.points[:, 2]
pl = pv.Plotter()
pl.cad.add(mb, scalars='Z', cmap='viridis')
pl.show()
inspect step assembly

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