Per-object names round-trip through 3MF

Per-object names round-trip through 3MF#

3MF stores one <object> per mesh. When you write a pyvista.MultiBlock, every block name and cad.label is preserved on the way in and on the way out.

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) with seven named products, writes it to 3MF, and confirms names, units, and per-block metadata survive the round-trip.

from pathlib import Path
import tempfile

import pandas as pd
import pyvista as pv

import pyvista_cad
from pyvista_cad.examples import downloads

Read the real assembly: each part is a named block.

MultiBlock (0x7f6faa75f6a0)
  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


Write to 3MF, then read it back.

out = Path(tempfile.mkdtemp()) / 'amb2022_plate.3mf'
pyvista_cad.write_three_mf(mb_in, out, units='mm')
mb_out = pyvista_cad.read_three_mf(out)

rows = []
for key in mb_out.keys():  # noqa: SIM118
    block = mb_out[key]
    rows.append(
        {
            'key': key,
            'cells': block.n_cells,
            'guid': str(block.field_data['cad.guid'][0])[:8],
        }
    )
pd.DataFrame(rows)
key cells guid
0 AMMT_4x4x0_375_Substrate_Tapped 444 f18ecae3
1 AMB2022-01-AMMT-PartCAD 436 b2c88ef9
2 AMB2022-01-AMMT-PartCAD 436 b2c88ef9
3 AMB2022-01-AMMT-PartCAD 436 b2c88ef9
4 AMB2022-01-AMMT-PartCAD 436 b2c88ef9
5 AMB2022-01-AMMT-RecoaterGuideCAD 416 0444b871
6 AMB2022-01-AMMT-RecoaterGuideCAD 416 0444b871


Render the round-tripped assembly.

pl = pv.Plotter()
pl.add_mesh(mb_out, multi_colors=True, show_edges=True, edge_color='black')
pl.show()
color aware 3mf

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