visualdynamics.io.threemf¶
threemf
¶
Read and write 3MF meshes, a CAD export format that keeps parts and units.
A .3mf is a zip holding one XML model: triangles that are already
tessellated (read as tri3 face elements as they are), named objects
for an assembly's parts, each of which becomes a named element group,
and a declared unit, so there is nothing to ask at import. SolidWorks
writes it from Save As, so a SolidWorks model can be imported by
exporting it to 3MF; the native format is closed. STEP (io.step)
is read through a CAD kernel; 3MF needs none.
Assemblies are component references with affine transforms. They are
resolved recursively, so each placed instance of a part has its
triangles where the assembly put them. Only the standard library
(zipfile and xml.etree) and numpy are used.
Functions:
| Name | Description |
|---|---|
load |
Read a 3MF file as a geometry, one named element group per placed |
save |
Write the geometry's face elements as 3MF, one named object per |
Classes¶
Functions:¶
load
¶
load(path: str | PathLike) -> Geometry
Read a 3MF file as a geometry, one named element group per placed part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or path - like
|
The |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
Triangle face elements, converted from the file's declared unit
(millimeters when it declares none) with the units defined. There
is one element group per part instance the build places, named
with the part's own name, or 'object |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the file has no model document, declares a unit 3MF does not define, or places no meshes in its build. |
Source code in src/visualdynamics/io/threemf.py
save
¶
save(obj: Geometry, path: str | PathLike, unit_system: Any = None) -> None
Write the geometry's face elements as 3MF, one named object per element group.
The coordinates are written as stored. The file declares them in
meters when the geometry's units are defined, which is what they
are, and declares no unit when they are not, which 3MF reads as
millimeters.
unit_system is accepted because every exporter takes it, and is not
used, since the file declares its own unit. A geometry with no face
elements is refused with ValueError, as for STL.