From fe850502f4d27ae1f004bce52bc3922a4b952c58 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Fri, 4 Sep 2020 16:43:06 +0200 Subject: [PATCH] Change add interface to be more generic --- cadquery/assembly.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cadquery/assembly.py b/cadquery/assembly.py index 2827d02b..6d9e2aa9 100644 --- a/cadquery/assembly.py +++ b/cadquery/assembly.py @@ -69,11 +69,18 @@ class Assembly(object): self.objects = {self.name: self.obj} @overload - def add(self, obj: "Assembly") -> "Assembly": + def add( + self, + obj: "Assembly", + loc: Optional[Location] = None, + name: Optional[str] = None, + ) -> "Assembly": """ add a subassembly to the current assembly. :param obj: subassembly to be added + :param loc: location of the root object (deafault: None, resulting in the location stored in the subassembly being used) + :param name: unique name of the root object (default: None, resulting in the name stored in the subassembly being used) """ ... @@ -89,16 +96,27 @@ class Assembly(object): :param obj: object to be added as a subassembly :param loc: location of the root object (deafault: None, interpreted as identity transformation) - :param name: unique name of the root object (default: None, reasulting in an UUID being generated) + :param name: unique name of the root object (default: None, resulting in an UUID being generated) """ ... def add(self, arg, **kwargs): if isinstance(arg, Assembly): - self.children.append(arg) - self.objects[arg.name] = arg.obj - self.objects.update(arg.objects) + + subassy = Assembly( + arg.obj, + kwargs["loc"] if kwargs.get("loc") else arg.loc, + kwargs["name"] if kwargs.get("name") else arg.name, + ) + + subassy.children.extend(arg.children) + subassy.objects[subassy.name] = subassy.obj + subassy.objects.update(arg.objects) + + self.children.append(subassy) + self.objects[subassy.name] = subassy.obj + self.objects.update(subassy.objects) arg.parent = self