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)