Search code examples
c#ifcxbim

List of all different IfcEntities in IfcFile


Summary

  • i have an ifc file with different IfcEntities like IfcWall, IfcBeam, IfcColumn etc.
  • i'm struggling to find a way to list all different entities in this ifc file
  • the list should contain every ifcentity occurence just once {"IfcWall", "IfcColumn", "IfcBeam", ...}
  • debugged also the code to see if there was any property which held the value i was searching for

My Code:

  • i've used the xbim Essential quick start guide
  • googled also
  • looked through the issues on github
using (var model = IfcStore.Open(_FilePath))
{
    var allInstances = model.Instances;
    var testList = model.Instances.OfType<IIfcBuildingElement>();

    var nameList = new List<string>();
    var objTypeList = new List<string>();
    foreach (var item in testList)
    {
        var objType = item.IsTypedBy;
        var firstObjType = objType.ElementAt(0);
        var relType = firstObjType.RelatingType;

        var name = item.Name;
        nameList.Add(name);
    }
}

What i expect:

  • simple list with all IfcEntities
  • like {"IfcWall", "IfcColumn", "IfcBeam", ...}

Would appreciate any help


Solution

  • thanks to @martin1cerny

    the answer was quite simple:

    var testList = model.Instances.OfType<IIfcBuildingElement>().GroupBy(e => e.GetType());
    

    issue/question on github