0

通过使用 ifchopenshell,我可以使用此代码轻松遍历所有楼层

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

但是,对于每一层,我想找到属于它的所有 IfcSpace 类型的 Ifc 元素。

我该如何查询这个?谢谢你。

4

1 回答 1

0

我终于用这段代码解决了它:

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)
于 2021-04-02T17:28:15.257 回答