From 8ee60db0dfc2d203ff68f2f1cf3dd6bfd6056f38 Mon Sep 17 00:00:00 2001 From: Sigma Dimensions <79010126+myoualid@users.noreply.github.com> Date: Wed, 15 Feb 2023 23:11:30 +0100 Subject: [PATCH] Re-assigning a product type class should also reassign the class of its typed instances --- .../ifcopenshell/api/root/reassign_class.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py index 4a8d79c4bb..ae2843479d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/reassign_class.py @@ -18,10 +18,17 @@ import ifcopenshell import ifcopenshell.util.schema +import ifcopenshell.util.element class Usecase: - def __init__(self, file, product=None, ifc_class="IfcBuildingElementProxy", predefined_type=None): + def __init__( + self, + file, + product=None, + ifc_class="IfcBuildingElementProxy", + predefined_type=None, + ): """Changes the class of a product If you ever created a wall then realised it's meant to be something @@ -71,4 +78,13 @@ class Usecase: except: element.PredefinedType = "USERDEFINED" element.ObjectType = self.settings["predefined_type"] + if element.is_a("IfcTypeProduct"): + for typed_element in ifcopenshell.util.element.get_types(element) or []: + ifcopenshell.api.run( + "root.reassign_class", + self.file, + product=typed_element, + ifc_class=self.settings["ifc_class"].strip("Type"), + predefined_type= self.settings["predefined_type"] + ) return element