2

我正在尝试检索存储在 IFC 文件中的每个项目中的所有属性,类似于您在 xbim 资源管理器中选择一个项目并获得所有数据(例如 Type、DefiningType、GlobalID 等)时看到的内容。

xbim 文档包含一个相关示例:

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}");
}

但是,上面的代码在使用 Ifc2x3 内核时无法编译。而且我的 IFC 模型不适用于 Ifc4。

Ifc2x3 等价于什么

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

或者更好的是,如何循环 IFC 模型中的每个项目并检索每个项目的所有属性(Ifc2x3)?

4

1 回答 1

0

Ifc2x3 等价物是什么

您只需将: theDoor.IsDefinedBy 替换为 theDoor.IsDefinedByProperties

于 2021-06-22T15:12:43.597 回答