2

I am trying to retrieve all the properties in every item stored in an IFC file, similar to what you see when you select an item in xbim explorer and you get all data such as Type, DefiningType, GlobalID and so on.

The xbim docs contains a relevant example:

using System;
using System.Linq;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;

const string fileName = "SampleHouse.ifc";
using (var model = IfcStore.Open(fileName))
{
    //get one single door 
    var id = "2AswZfru1AdAiKfEdrNPnu";
    var theDoor = model.Instances.FirstOrDefault<IIfcDoor>(d => d.GlobalId == id);
    Console.WriteLine($"Door ID: {theDoor.GlobalId}, Name: {theDoor.Name}");

    //get all single-value properties of the door
    var properties = theDoor.IsDefinedBy
        .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
        .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
        .OfType<IIfcPropertySingleValue>();
    foreach (var property in properties)
        Console.WriteLine($"Property: {property.Name}, Value: {property.NominalValue}");
}

However, the code above does not compile when using the Ifc2x3 kernel. And my IFC model does not work with Ifc4.

What is the Ifc2x3 equivalent of

    var properties = theDoor.IsDefinedBy
        .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
        .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
        .OfType<IIfcPropertySingleValue>();

Or even better, how to loop ever every item in the IFC model and retrieve all properies for each one (Ifc2x3)?

sinsro
  • 192
  • 1
  • 10
  • What do you mean by 'However, the code above does not compile when using the Ifc2x3 kernel'? Do you get any compiler errors? IFC2x3 schema implementation in xbim also implements IFC4 interfaces, so this code will work fine with IFC2x3 data. – Martin Cerny Feb 08 '21 at 14:10

1 Answers1

0

What is the Ifc2x3 equivalent

You just need to replace: theDoor.IsDefinedBy by theDoor.IsDefinedByProperties