Walk a real STEP assembly

Walk a real STEP assembly#

The cad accessor on MultiBlock provides three traversal helpers: walk yields (path, block) pairs, find filters by glob or metadata predicates, and flatten collapses the tree to a single-level container with path-named entries.

This walks 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 with four bridge specimens and two recoater guides, each a named product, exactly the structure that lands on a developer’s desk.

import pandas as pd
import pyvista as pv

import pyvista_cad
from pyvista_cad.examples import downloads

Load the real STEP assembly.

MultiBlock (0x7f6faa972bc0)
  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 leaf is a named product.

rows = []
for path, block in root.cad.walk():
    rows.append(
        {
            'path': str(path),
            'kind': type(block).__name__,
            'label': block.field_data.get('cad.label', [b''])[0],
            'cells': block.n_cells if isinstance(block, pv.DataSet) else 0,
        }
    )

pd.DataFrame(rows)
path kind label cells
0 AMMT_4x4x0_375_Substrate_Tapped PolyData AMMT_4x4x0_375_Substrate_Tapped 444
1 AMB2022-01-AMMT-PartCAD PolyData AMB2022-01-AMMT-PartCAD 436
2 AMB2022-01-AMMT-PartCAD PolyData AMB2022-01-AMMT-PartCAD 436
3 AMB2022-01-AMMT-PartCAD PolyData AMB2022-01-AMMT-PartCAD 436
4 AMB2022-01-AMMT-PartCAD PolyData AMB2022-01-AMMT-PartCAD 436
5 AMB2022-01-AMMT-RecoaterGuideCAD PolyData AMB2022-01-AMMT-RecoaterGuideCAD 416
6 AMB2022-01-AMMT-RecoaterGuideCAD PolyData AMB2022-01-AMMT-RecoaterGuideCAD 416


Filter by label glob (“give me every bridge specimen”), the same pattern as globbing a BOM for 'M5_*'.

bridges = root.cad.find('*PartCAD*')
pd.DataFrame({'path': [str(p) for p, _ in bridges]})
path
0 AMB2022-01-AMMT-PartCAD
1 AMB2022-01-AMMT-PartCAD
2 AMB2022-01-AMMT-PartCAD
3 AMB2022-01-AMMT-PartCAD


Flatten to a single level.

list(root.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 the source assembly CAD-friendly: shaded faces with the topological edges overlaid, one colour per part.

pl = pv.Plotter()
pl.cad.add(root, multi_colors=True)
pl.show()
multiblock walk

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