0

I have to extract some convection coolers out of an ifc-file. They're saved as BildingElementProxys & are in relation with IfcRelContainedInSpatialStructure. My approach is to get all the IfcRelContainedInSpatialStructures & search with a for-loop through the RelatedObjects if there are objects which are also an IfcBuildingElementProxy. But I'm not which excact commands I got to use for the for-loop. Would be great if someone could help

That's what I've got so far:

import ifcopenshell
import ifcopenshell.util
from ifcopenshell.util.selector import Selector
import ifcopenshell.file

ifc = ifcopenshell.open(...)

selector = Selector()
buildingelementproxies = selector.parse(ifc, ".IfcBuildingElementProxy")
spaces = selector.parse(ifc, ".IfcSpace")
containedrelation = selector.parse(ifc, ".IfcRelContainedInSpatialStructure")
print (containedrelation)
julia
  • 1
  • 1

1 Answers1

0

Assuming you want to get all proxies together with the spatial structure (e.g. storey) they are contained in, you have 3 options.

  1. Start from relations as suggested in your question.
for relation in containedrelation:
    for element in relation.RelatedElements:
        if element in buildingelementproxies:
            print(element.Name, "in", relation.RelatingStructure.Name) 
  1. Start from elements.
for element in buildingelementproxies:
    for relation in element.ContainedInStructure:
        print(element.Name, "in", relation.RelatingStructure.Name) 
  1. Start from structures.
spatialstructures = selector.parse(ifc, ".IfcSpatialStructureElement")
for structure in spatialstructures:
    for relation in structure.ContainsElements:
        for element in relation.RelatedElements:
            if element in buildingelementproxies:
                print(element.Name, "in", structure.Name)

Similarly you can use list comprehension to get the pairs of element and spatial structure.

[(element.Name, relation.RelatingStructure.Name) for relation in containedrelation for element in relation.RelatedElements if element in buildingelementproxies]
[(element.Name, relation.RelatingStructure.Name) for element in buildingelementproxies for relation in element.ContainedInStructure]
[(element.Name, structure.Name) for structure in spatialstructures for relation in structure.ContainsElements for element in relation.RelatedElements if element in buildingelementproxies]
hlg
  • 1,321
  • 13
  • 29