From ab80400e16d25513facb87444fc6b4bae4b2168b Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 21 Jan 2024 21:56:45 +1100 Subject: [PATCH] See #4240. Guard against possible user creating invalid userdefined attribute values. --- .../ifcopenshell/api/attribute/edit_attributes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/attribute/edit_attributes.py b/src/ifcopenshell-python/ifcopenshell/api/attribute/edit_attributes.py index 120139511c..83bc15f0ec 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/attribute/edit_attributes.py +++ b/src/ifcopenshell-python/ifcopenshell/api/attribute/edit_attributes.py @@ -50,5 +50,18 @@ class Usecase: def execute(self): for name, value in self.settings["attributes"].items(): setattr(self.settings["product"], name, value) + if hasattr(self.settings["product"], "PredefinedType"): + if hasattr(self.settings["product"], "ElementType"): + if ( + not self.settings["product"].ElementType + and self.settings["product"].PredefinedType == "USERDEFINED" + ): + self.settings["product"].PredefinedType = "NOTDEFINED" + elif hasattr(self.settings["product"], "ObjectType"): + if ( + not self.settings["product"].ObjectType + and self.settings["product"].PredefinedType == "USERDEFINED" + ): + self.settings["product"].PredefinedType = "NOTDEFINED" if hasattr(self.settings["product"], "OwnerHistory"): ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": self.settings["product"]})