XbimEssentials
XbimEssentials copied to clipboard
Obtaining elements related to another element.
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 ;)
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.
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?
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.");
}
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 :)
note that my IFC file is exported from Revit.
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.