From 03c3266b8d61d487349a15f73d3b3cb13bce625f Mon Sep 17 00:00:00 2001 From: FB Date: Wed, 26 Oct 2022 06:41:58 +0200 Subject: [PATCH] Add STL to Assemblys export formats (#1101) * Add STL to Assemblys export formats Turn the assembly into a compound and use Shapes export method to export the assembly. This way the export function does not need to be duplicated, and it is what users have been doing manually to get their objects. * Add STL to test matrix Co-authored-by: AU --- cadquery/assembly.py | 6 ++++-- tests/test_assembly.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cadquery/assembly.py b/cadquery/assembly.py index 8563926c7..45033179b 100644 --- a/cadquery/assembly.py +++ b/cadquery/assembly.py @@ -27,7 +27,7 @@ # type definitions AssemblyObjects = Union[Shape, Workplane, None] -ExportLiterals = Literal["STEP", "XML", "GLTF", "VTKJS", "VRML"] +ExportLiterals = Literal["STEP", "XML", "GLTF", "VTKJS", "VRML", "STL"] PATH_DELIM = "/" @@ -453,7 +453,7 @@ def save( if exportType is None: t = path.split(".")[-1].upper() - if t in ("STEP", "XML", "VRML", "VTKJS", "GLTF"): + if t in ("STEP", "XML", "VRML", "VTKJS", "GLTF", "STL"): exportType = cast(ExportLiterals, t) else: raise ValueError("Unknown extension, specify export type explicitly") @@ -468,6 +468,8 @@ def save( exportGLTF(self, path, True, tolerance, angularTolerance) elif exportType == "VTKJS": exportVTKJS(self, path) + elif exportType == "STL": + self.toCompound().exportStl(path, tolerance, angularTolerance) else: raise ValueError(f"Unknown format: {exportType}") diff --git a/tests/test_assembly.py b/tests/test_assembly.py index c107de84c..67d017a51 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -247,6 +247,7 @@ def test_toJSON(simple_assy, nested_assy, empty_top_assy): ("stp", ("STEP",)), ("caf", ("XML",)), ("wrl", ("VRML",)), + ("stl", ("STL",)), ], ) def test_save(extension, args, nested_assy, nested_assy_sphere):