diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index aa52b029c8..63b6b79d5c 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -78,6 +78,12 @@ def get_type(element): return relationship.RelatingType +def get_types(type): + for rel in getattr(type, "Types", []): + return rel.RelatedObjects + return [] + + def get_material(element, should_skip_usage=False): if hasattr(element, "HasAssociations") and element.HasAssociations: for relationship in element.HasAssociations: diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index d3f9c23158..855a0e9e59 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -136,6 +136,14 @@ class TestGetTypeIFC2X3(test.bootstrap.IFC2X3): assert subject.get_type(element_type) == element_type +class TestGetTypes(test.bootstrap.IFC4): + def test_getting_the_type_of_a_product(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type) + assert subject.get_types(element_type) == (element,) + + class TestGetMaterial(test.bootstrap.IFC4): def test_getting_the_material_of_a_product(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")