yapcad.io package

Submodules

yapcad.io.geometry_json module

Geometry JSON serialization/deserialization helpers.

Implements the draft schema described in docs/geometry_json_schema.md.

yapcad.io.geometry_json.geometry_from_json(doc: Dict[str, Any]) List[list][source]

Deserialize geometry JSON into yapCAD list structures.

yapcad.io.geometry_json.geometry_to_json(entities: Iterable[list], *, units: str | None = None, generator: Dict[str, Any] | None = None, relationships: List[Dict[str, Any]] | None = None, attachments: List[Dict[str, Any]] | None = None) Dict[str, Any][source]

Serialize solids/surfaces into the geometry JSON document.

yapcad.io.step module

STEP export utilities for yapCAD surfaces and solids.

yapcad.io.step.write_step(obj: Sequence, path_or_file, *, name: str = 'yapCAD', schema: str = 'AUTOMOTIVE_DESIGN_CC2') None[source]

Export obj (surface or solid) to a STEP file using a faceted BREP.

yapcad.io.step.write_step_analytic(obj: Sequence, path: str, *, name: str = 'yapCAD', fallback_to_faceted: bool = True) bool[source]

Export obj to a STEP file using analytic BREP if available.

This function attempts to export the object using its native BREP representation (with analytic surfaces like planes, cylinders, spheres). If native BREP data is not available or OCC is not installed, it can fall back to faceted BREP export.

Parameters:
  • obj (Sequence) – A yapCAD solid or surface to export.

  • path (str) – The output file path.

  • name (str, optional) – The product name in the STEP file. Default ‘yapCAD’.

  • fallback_to_faceted (bool, optional) – If True and analytic export fails, fall back to faceted export. Default True.

Returns:

True if analytic export succeeded, False if fell back to faceted.

Return type:

bool

Raises:
  • RuntimeError – If OCC is not available and fallback_to_faceted is False.

  • ValueError – If native BREP is not available and fallback_to_faceted is False.

yapcad.io.step_importer module

STEP import utilities backed by pythonocc-core.

yapcad.io.step_importer.import_step(path) List[Geometry][source]

Read a STEP file and return a list of yapCAD Geometry objects.

Parameters:

path – filesystem path or string to the STEP file.

yapcad.io.stl module

STL import and export utilities for yapCAD surfaces and solids.

yapcad.io.stl.import_stl(path: str, *, deduplicate: bool = True) list[source]

Import an STL file as a yapCAD solid.

This is an alias for read_stl() for API consistency with yapcad.io.step_importer.import_step().

Parameters:
  • path (str) – Path to STL file.

  • deduplicate (bool, optional) – If True (default), merge coincident vertices.

Returns:

yapCAD solid containing the imported mesh.

Return type:

solid

yapcad.io.stl.read_stl(path_or_file, *, deduplicate: bool = True) list[source]

Read an STL file and return a yapCAD solid.

Parameters:
  • path_or_file (str or path-like or file-like) – Path to STL file, or an open binary file object.

  • deduplicate (bool, optional) – If True (default), merge coincident vertices to create a proper indexed mesh. If False, each triangle gets its own vertices.

Returns:

yapCAD solid containing a single surface with the imported mesh. The solid structure is: [‘solid’, [surface], boundary, holes]

Return type:

solid

Examples

>>> from yapcad.io.stl import read_stl, write_stl
>>> my_solid = read_stl('model.stl')
>>> # Round-trip: export and re-import
>>> write_stl(my_solid, 'copy.stl')
>>> copy_solid = read_stl('copy.stl')
yapcad.io.stl.write_stl(obj: Sequence, path_or_file, *, binary: bool = True, name: str = 'yapCAD') None[source]

Write obj (surface or solid) to STL.

path_or_file can be a filesystem path or an open binary/text stream.

Module contents

I/O utilities for yapCAD.

yapcad.io.write_step(obj: Sequence, path_or_file, *, name: str = 'yapCAD', schema: str = 'AUTOMOTIVE_DESIGN_CC2') None[source]

Export obj (surface or solid) to a STEP file using a faceted BREP.

yapcad.io.write_stl(obj: Sequence, path_or_file, *, binary: bool = True, name: str = 'yapCAD') None[source]

Write obj (surface or solid) to STL.

path_or_file can be a filesystem path or an open binary/text stream.