简体   繁体   中英

Getting all properties of object using Ifc2x3

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)?

What is the Ifc2x3 equivalent

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM