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_brepfirst -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: oneIfcBuildingElementProxyper 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
¤
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 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 |
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 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. |
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. |
required |
formats
|
iterable[str]
|
Suffixes, with or without the dot. |
('stp', 'obj', 'ifc')
|
preview
|
:class:`compas.datastructures.Mesh`
|
One mesh to write on its own as |
None
|
**kwargs
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, :class:`pathlib.Path`]
|
Every file written, keyed by suffix ( |
Examples:
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 |
required |
author
|
str
|
Author recorded in the STEP header. |
'compas_tf'
|
**kwargs
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
class:`pathlib.Path`
|
The file written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no mesh survives (nothing to write). |