Skip to content

compas_tf.writer ¤

Write element geometry to the files a shop and the docs need.

One place for the export half of a fabrication example, so every element does it the same way. Four formats, each for a different reader:

  • STEP is the CAD hand-off. The booleans that carve an element leave triangle soup, so the meshes go through :func:compas_tf.brep.meshes_to_brep first - compas_occt's coplanar-face merge behind a volume guard - and the flat faces the part was modelled with come back as single Brep faces.
  • OBJ (or PLY/STL/OFF) is the mesh the element already is, no kernel involved. Every solid keeps its name, so the file lands as identifiable pieces rather than one blob.
  • IFC is the BIM hand-off, written with compas_ifc: one IfcBuildingElementProxy per solid inside a minimal project/site/building/storey template, millimetres, IFC4.
  • A preview is one mesh on its own, for the viewer embedded in the docs. Same mesh formats; the viewer reads them directly, which is why nothing here needs glTF.

Nothing in here computes geometry. Hand it meshes that are already placed and carved - see examples/example_model_12_fab_column.py.

Functions:¤

triangulated ¤

triangulated(mesh: Mesh) -> Mesh

A copy of mesh with every ngon face ear-clipped to triangles.

The coplanar-face merge leaves concave polygon faces; web viewers fan-triangulate ngons and smear triangles across the concavities, so a mesh meant for the docs viewer goes through this first. Reuses the ear-clipping the plate caps already use.

write_ifc ¤

write_ifc(meshes: Iterable[Mesh], filepath: str | Path, schema: str = 'IFC4') -> Path

Write meshes to one IFC file via compas_ifc.

Every mesh becomes one IfcBuildingElementProxy (named after the mesh) on the single storey of a minimal template project, in millimetres.

Parameters:

Name Type Description Default
meshes iterable[:class:`compas.datastructures.Mesh`]

The solids to write.

required
filepath str | :class:`pathlib.Path`

Destination .ifc file.

required
schema str

IFC schema version.

'IFC4'

Returns:

Type Description
class:`pathlib.Path`

The file written.

Raises:

Type Description
ValueError

If no mesh survives (nothing to write).

write_mesh ¤

write_mesh(meshes: Iterable[Mesh], filepath: str | Path) -> Path

Write meshes to one mesh file, format chosen by the suffix.

Parameters:

Name Type Description Default
meshes iterable[:class:`compas.datastructures.Mesh`]

The meshes to write.

required
filepath str | :class:`pathlib.Path`

Destination file. .obj, .ply, .stl or .off. Only OBJ keeps several meshes as separate named groups; the others are written from the first mesh, so join before calling if that matters.

required

Returns:

Type Description
class:`pathlib.Path`

The file written.

Raises:

Type Description
ValueError

If the suffix is not a supported mesh format, or nothing to write.

write_parts ¤

write_parts(meshes: Iterable[Mesh], directory: str | Path, name: str, formats: Iterable[str] = ('stp', 'obj', 'ifc'), preview: Mesh | None = None, **kwargs) -> dict

Write one element's fabrication set: the solids, plus a docs preview.

The whole export half of a fabrication example in one call.

Parameters:

Name Type Description Default
meshes iterable[:class:`compas.datastructures.Mesh`]

Every solid that belongs to the element - the stock, the carved part, the cutters. Written to each requested format.

required
directory str | :class:`pathlib.Path`

Where the files go. Created if missing.

required
name str

Stem for the files, e.g. "column_0" gives column_0_fab.stp.

required
formats iterable[str]

Suffixes, with or without the dot. "stp"/"step" go through the Brep merge, "ifc" goes through :func:write_ifc; the mesh formats are written as-is.

('stp', 'obj', 'ifc')
preview :class:`compas.datastructures.Mesh`

One mesh to write on its own as <name>_preview.obj, for the viewer in the docs. Usually the finished part: the stock encloses it and the cutters pass through it, so all the solids at once would show nothing. Triangulated on the way out - web viewers fan-triangulate the merged concave faces and draw garbage. None writes no preview.

None
**kwargs

Forwarded to :func:write_step.

{}

Returns:

Type Description
dict[str, :class:`pathlib.Path`]

Every file written, keyed by suffix ("stp", "obj", ...), with the preview under "preview".

Examples:

>>> write_parts([stock, part] + cutters, fab_dir, "column_0", preview=part)
{'stp': ..., 'obj': ..., 'preview': ...}

write_step ¤

write_step(meshes: Iterable[Mesh], filepath: str | Path, author: str = 'compas_tf', **kwargs) -> Path

Write meshes to one STEP file, coplanar faces merged.

Parameters:

Name Type Description Default
meshes iterable[:class:`compas.datastructures.Mesh`]

The solids to write. Several become a compound, one solid each.

required
filepath str | :class:`pathlib.Path`

Destination .stp / .step file.

required
author str

Author recorded in the STEP header.

'compas_tf'
**kwargs

Forwarded to :func:compas_tf.brep.meshes_to_brep - e.g. merge_coplanar=False to keep the raw triangles, or a looser angulardeflection.

{}

Returns:

Type Description
class:`pathlib.Path`

The file written.

Raises:

Type Description
ValueError

If no mesh survives (nothing to write).