Skip to content

Commit

Permalink
Add STL to Assemblys export formats (#1101)
Browse files Browse the repository at this point in the history
* 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 <adam-urbanczyk@users.noreply.github.com>
  • Loading branch information
qwelyt and adam-urbanczyk authored Oct 26, 2022
1 parent 8ddad3b commit 03c3266
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cadquery/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/"

Expand Down Expand Up @@ -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")
Expand All @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 03c3266

Please sign in to comment.