XbimEssentials icon indicating copy to clipboard operation
XbimEssentials copied to clipboard

Obtaining elements related to another element.

Open cafecodingir opened this issue 3 years ago • 6 comments

Hi xBimTeam I want to get all the window element IDs that belong to a wall, or all the rebars of a concrete wall or a foundation. How can I do that?

Best ;)

cafecodingir avatar Oct 26 '21 16:10 cafecodingir

Hi @cafecodingir. Getting all windows in the wall should be relatively straightforward. You can use semantic relations IfcRelVoidsElement and IfcRelFillsElement. To get all rebars you might be able to use IfcRelAggregates depending on how the authoring tool created and exported the wall or foundation. Or, you can analyse the geometry. It would effectively be a clash detection task. To do this, I'd recommend to use bounding boxes for first fast iteration (find all the candidates) and then run the precise analyses.

martin1cerny avatar Nov 01 '21 07:11 martin1cerny

I apologize for being a beginner, but I do not know how to use these items, may you give me a simple code as a sample?

cafecodingir avatar Nov 03 '21 09:11 cafecodingir

This is how you would get all windows in a wall:

foreach (var wall in model.Instances.OfType<IIfcWall>())
{
    var windows = wall.HasOpenings
        .Select(rel => rel.RelatedOpeningElement)
        .OfType<IIfcOpeningElement>()
        .SelectMany(o => o.HasFillings)
        .Select(rel => rel.RelatedBuildingElement)
        .OfType<IIfcWindow>()
        .ToList();
    Console.WriteLine($"Wall #{wall.EntityLabel} has {windows.Count} windows.");
}

martin1cerny avatar Nov 03 '21 10:11 martin1cerny

Thank you very much for your response Martin, but I'd be very grateful if you'd provide me the same code for the foundation rebars too.

Best :)

cafecodingir avatar Nov 03 '21 17:11 cafecodingir

note that my IFC file is exported from Revit.

cafecodingir avatar Nov 03 '21 18:11 cafecodingir

I'm sorry, but I can't provide the code for all scenarios. You will be best to inspect the file to see how it is modelled and if there is any similar semantic relationship between rebars and foundations. You can then implement similar code to traverse these relations.

martin1cerny avatar Nov 04 '21 08:11 martin1cerny