0

By using ifchopenshell I can easily traverse all storeys using this code

for ifc_storey in ifc_file.by_type("IfcBuildingStorey"):
    print(str(ifc_storey.Name))

However, for each storey I would like to find all the Ifc elements of type IfcSpace, that belongs to it.

How can I query this? Thank you.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
sinsro
  • 192
  • 1
  • 10

1 Answers1

1

I finally solved it using this code:

def getChildrenOfType(ifcParentElement,ifcType):
    items=[]
    if type(ifcType) != list:
        ifcType=[ifcType]
    _getChildrenOfType(items,ifcParentElement,ifcType,0)
    return items

def _getChildrenOfType(targetList,element,ifcTypes,level):
    # follow Spatial relation
    if (element.is_a('IfcSpatialStructureElement')):
        for rel in element.ContainsElements:
            relatedElements = rel.RelatedElements
            for child in relatedElements:
                _getChildrenOfType(targetList,child, ifcTypes, level + 1)
    # follow Aggregation Relation
    if (element.is_a('IfcObjectDefinition')):
        for rel in element.IsDecomposedBy:
            relatedObjects = rel.RelatedObjects
            for child in relatedObjects:
                _getChildrenOfType(targetList,child, ifcTypes, level + 1)
    for typ in ifcTypes:
        if (element.is_a(typ)):
            targetList.append(element)
sinsro
  • 192
  • 1
  • 10