ifcopenshell.util.element.get_structure_referenced_elements

This commit is contained in:
Andrej730
2024-04-15 17:12:16 +05:00
parent 9954e073fa
commit ff76850a54
2 changed files with 37 additions and 0 deletions
@@ -904,6 +904,27 @@ def get_referenced_structures(element: ifcopenshell.entity_instance) -> list[ifc
return [r.RelatingStructure for r in getattr(element, "ReferencedInStructures", [])]
def get_structure_referenced_elements(structure: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]:
"""Retreives a set of elements referenced by a structure
:param structure: IfcSpatialElement
:type element: ifcopenshell.entity_instance.entity_instance
:return: A set of referenced elements, IfcSpatialReferenceSelect
:rtype: set[ifcopenshell.entity_instance.entity_instance]
Example:
.. code:: python
element = file.by_type("IfcBuildingStorey")[0]
print(ifcopenshell.util.element.get_structure_referenced_elements(element))
"""
referenced = set()
for rel in structure.ReferencesElements:
referenced.update(rel.RelatedElements)
return referenced
def get_decomposition(element: ifcopenshell.entity_instance, is_recursive=True) -> list[ifcopenshell.entity_instance]:
"""
Retrieves all subelements of an element based on the spatial decomposition
@@ -726,6 +726,22 @@ class TestGetReferencedStructures(test.bootstrap.IFC4):
assert subject.get_referenced_structures(element) == [building, building2]
class TestGetStructureReferencedElements(test.bootstrap.IFC4):
def test_getting_references_of_an_element(self):
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
assert subject.get_structure_referenced_elements(building) == set()
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.reference_structure", self.file, product=element, relating_structure=building)
assert subject.get_structure_referenced_elements(building) == {element}
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.reference_structure", self.file, product=element2, relating_structure=building)
assert subject.get_structure_referenced_elements(building) == {element, element2}
class TestGetStructureReferencedElementsIFC2X3(test.bootstrap.IFC2X3, TestGetStructureReferencedElements):
pass
class TestGetDecompositionIFC4(test.bootstrap.IFC4):
def test_getting_decomposed_subelements_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")