Can anyone please verify my code to load Ifc Structure
umarone opened this issue · comments
public static void Show()
{
const string file = "IfcImages/ModernDiningRoom.ifc";
using (var model = IfcStore.Open(file))
{
var project = model.Instances.ToList();
LoadIfcStructure(project);
}
}
private static void structuraldataPartOneLoadRelaggregates(List<IPersistEntity> listInstances)
{
if (listInstances != null && listInstances.Count > 0)
{
foreach (var item in listInstances)
{
var spatialElement = item as IIfcObjectDefinition;
if (spatialElement != null)
{
if (spatialElement.IsDecomposedBy.SelectMany(r => r.RelatedObjects).Count() > 0)
{
spatialElement.GetType().Name
}
foreach (var ele in spatialElement.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
{
var oElement = ele as IIfcSpatialStructureElement;
if (oElement != null)
{
oElement.GetType().Name ;
Console.WriteLine(string.Format("{0} -> {1}", oElement.Name, oElement.GetType().Name));
//using IfcRelContainedInSpatialElement to get contained elements
var containedElements = oElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
if (containedElements != null)
{
foreach (var element in containedElements)
{
Console.WriteLine(string.Format("{0} -> {1}", element.Name, element.GetType().Name));
}
}
}
else
{
console.writeline (ele.Name);
}
}
}
}
}
}
Dear Sir.
I have uploaded my code, please see if my code is fine. My code is giving me result but not in a good tree structure as OPEN IFC Viewer is giving
I found an example of loading spatial structure and i changed it according to my need. if you can correct the code please do help me
Please if anyone can see my code or if anyone can give his spatial structure reading code.
See https://docs.xbim.net/examples/spatial-hierarchy.html and https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD1/HTML/link/ifcspatialstructureelement.htm
I can't make a lot of sense of the above code. You've not provided LoadIfcStructure()
You generally need to use recursion to descent the nested hierarchy as per https://github.com/xBimTeam/XbimSamples/blob/2108efba47e628207c92e5ac23e1711b5de0ec99/BasicCreate/SpatialStructure.cs#L56