From c405ff1adf75df7f00f5703cc1be29f361f9d1cb Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 23 May 2024 23:08:53 +1000 Subject: [PATCH] Fix unassign_representation to not incorrectly use remove_deep without first removing known inverses. In theory, it would be possible for the representation map to be used elsewhere, then file.remove(representation_map) would cause problems. --- .../api/geometry/unassign_representation.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py index 435ea5207c..8473934821 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py @@ -47,17 +47,25 @@ class Usecase: product.Representation.Representations = representations def unassign_type_representation(self): + + matching_representation_map = None + representation_maps = self.settings["product"].RepresentationMaps or [] + for representation_map in self.settings["product"].RepresentationMaps or []: if representation_map.MappedRepresentation == self.settings["representation"]: - self.unassign_products_using_mapped_representation(representation_map) - self.remove_representation_map_only(representation_map) + matching_representation_map = representation_map break - self.settings["product"].RepresentationMaps = self.settings["product"].RepresentationMaps or None + + if matching_representation_map: + self.unassign_products_using_mapped_representation(matching_representation_map) + self.settings["product"].RepresentationMaps = [ + rm for rm in self.settings["product"].RepresentationMaps if rm != matching_representation_map + ] or None + self.remove_representation_map_only(matching_representation_map) def remove_representation_map_only(self, representation_map): representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation() ifcopenshell.util.element.remove_deep2(self.file, representation_map) - self.file.remove(representation_map) def unassign_products_using_mapped_representation(self, representation_map): mapped_representations = []