Skip to content

Commit 03c3266

Browse files
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 <[email protected]>
1 parent 8ddad3b commit 03c3266

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cadquery/assembly.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# type definitions
2929
AssemblyObjects = Union[Shape, Workplane, None]
30-
ExportLiterals = Literal["STEP", "XML", "GLTF", "VTKJS", "VRML"]
30+
ExportLiterals = Literal["STEP", "XML", "GLTF", "VTKJS", "VRML", "STL"]
3131

3232
PATH_DELIM = "/"
3333

@@ -453,7 +453,7 @@ def save(
453453

454454
if exportType is None:
455455
t = path.split(".")[-1].upper()
456-
if t in ("STEP", "XML", "VRML", "VTKJS", "GLTF"):
456+
if t in ("STEP", "XML", "VRML", "VTKJS", "GLTF", "STL"):
457457
exportType = cast(ExportLiterals, t)
458458
else:
459459
raise ValueError("Unknown extension, specify export type explicitly")
@@ -468,6 +468,8 @@ def save(
468468
exportGLTF(self, path, True, tolerance, angularTolerance)
469469
elif exportType == "VTKJS":
470470
exportVTKJS(self, path)
471+
elif exportType == "STL":
472+
self.toCompound().exportStl(path, tolerance, angularTolerance)
471473
else:
472474
raise ValueError(f"Unknown format: {exportType}")
473475

tests/test_assembly.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def test_toJSON(simple_assy, nested_assy, empty_top_assy):
247247
("stp", ("STEP",)),
248248
("caf", ("XML",)),
249249
("wrl", ("VRML",)),
250+
("stl", ("STL",)),
250251
],
251252
)
252253
def test_save(extension, args, nested_assy, nested_assy_sphere):

0 commit comments

Comments
 (0)