From faf489e9dc121044fbf9ffc9681f0f661e570876 Mon Sep 17 00:00:00 2001 From: Robin Quint Date: Sat, 9 Aug 2025 00:43:22 +0200 Subject: [PATCH] extended Root.copy_representation to also copy shape aspects --- src/bonsai/bonsai/tool/root.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index d7b7e0596f..3cc0091b15 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -102,6 +102,26 @@ class Root(bonsai.core.tool.Root): exclude_callback=exclude_callback, copied_entities=copied_entities, ) + + if source.Representation.is_a("IfcProductDefinitionShape"): + old_to_new_items = {} + for repr_index, representation in enumerate(source.Representation.Representations): + for item_index, item in enumerate(representation.Items): + old_to_new_items[item.id()] = dest.Representation.Representations[repr_index].Items[item_index] + + for aspect in source.Representation.HasShapeAspects: + new_reprs = [] + for repr in aspect.ShapeRepresentations: + new_items = [] + for old_item in repr.Items: + new_items.append(old_to_new_items[old_item.id()]) + new_repr = ifcopenshell.util.element.copy(tool.Ifc.get(), repr) + new_repr.Items = new_items + new_reprs.append(new_repr) + new_aspect = ifcopenshell.util.element.copy(tool.Ifc.get(), aspect) + new_aspect.ShapeRepresentations = new_reprs + new_aspect.PartOfProductDefinitionShape = dest.Representation + elif dest.is_a("IfcTypeProduct"): if not source.RepresentationMaps: return copied_entities