diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index f9cd4ef917..b21a58a7ce 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -79,6 +79,9 @@ def get_material(element, should_skip_usage=False): def get_container(element): + aggregate = get_aggregate(element) + if aggregate: + return get_container(aggregate) if hasattr(element, "ContainedInStructure") and element.ContainedInStructure: return element.ContainedInStructure[0].RelatingStructure diff --git a/src/ifcopenshell-python/test/api/style/test_edit_surface_style.py b/src/ifcopenshell-python/test/api/style/test_edit_surface_style.py index 23c38c8779..eb090e710d 100644 --- a/src/ifcopenshell-python/test/api/style/test_edit_surface_style.py +++ b/src/ifcopenshell-python/test/api/style/test_edit_surface_style.py @@ -3,7 +3,7 @@ import test.bootstrap import ifcopenshell.api -class TestEditStyleColours(test.bootstrap.IFC4): +class TestEditSurfaceStyle(test.bootstrap.IFC4): def test_editing_a_shading_style(self): colour = self.file.createIfcColourRgb(None, 0, 0, 0) style = self.file.createIfcSurfaceStyleShading(colour) diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index 320f0a2287..facfdd8093 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -165,6 +165,14 @@ class TestGetContainerIFC4(test.bootstrap.IFC4): ifcopenshell.api.run("spatial.assign_container", self.file, product=element, relating_structure=building) assert ifcopenshell.util.element.get_container(element) == building + def test_getting_an_indirect_spatial_container_of_an_element(self): + subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly") + building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding") + ifcopenshell.api.run("spatial.assign_container", self.file, product=element, relating_structure=building) + ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element) + assert ifcopenshell.util.element.get_container(subelement) == building + class TestGetAggregateIFC4(test.bootstrap.IFC4): def test_getting_the_containing_aggregate_of_a_subelement(self):