From 2029e40a7bc9df045dd15ac399598a13e749a33a Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Fri, 4 Sep 2020 11:46:56 +0200 Subject: [PATCH] Implemented save --- cadquery/assembly.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cadquery/assembly.py b/cadquery/assembly.py index efe5ef9f..31b5503b 100644 --- a/cadquery/assembly.py +++ b/cadquery/assembly.py @@ -5,10 +5,12 @@ from uuid import uuid1 as uuid from .cq import Workplane from .occ_impl.shapes import Shape from .occ_impl.geom import Location +from .occ_impl.exporters.assembly import exportAssembly, exportCAF AssemblyObjects = Union[Shape, Workplane, None] ConstraintKinds = Literal["Plane", "Point", "Axis"] +ExportLiterals = Literal["STEP", "XML"] class Constraint(object): @@ -90,9 +92,21 @@ class Assembly(object): raise NotImplementedError - def save(self, path: str): + def save(self, path: str, exportType: Optional[ExportLiterals] = None): - raise NotImplementedError + if exportType is None: + t = path.split(".")[-1].upper() + if t in ExportLiterals.__args__: + exportType = t + else: + raise ValueError("Unknown extension, specify export type explicitly") + + if exportType == "STEP": + exportAssembly(self, path) + elif exportType == "XML": + exportCAF(self, path) + else: + raise ValueError(f"Unknown format: {exportType}") def load(self, path: str):