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 = []