首页 > 解决方案 > 如何获取特定IfcElement的材质数据

问题描述

在 xbim 示例https://docs.xbim.net/examples/basic-model-operations.html的基本操作中,它显示了如何检索特定 IfcElement 的单值属性。基于此,我试图获取材料数据。

我写了以下内容:

var id = "3NBPkknun6EuV9fpeE6rFh";

var theWall = model.Instances.FirstOrDefault<IIfcElement>(d => d.GlobalId == id);

var materials = theWall.HasAssociations
                        .Where(r => r.RelatingMaterial is IIfcMaterialProfileSet)
                        .SelectMany(r=> ((IIfcMaterialProfileSet)r.RelatingMaterial).MaterialProfiles)
                        .OfType<IIfcMaterialProfile>();

它给了我这个错误:

“IIfcRelAssociates”不包含“RelatingMaterial”的定义,并且找不到接受“IIfcRelAssociates”类型的第一个参数的可访问扩展方法“RelatingMaterial”(您是否缺少 using 指令或程序集引用?)

我知道我必须使用 IfcRelAssociatesMaterial,但我不知道如何使用。如何检索材料信息?

标签: c#linqifcbimxbim

解决方案


IIfcObjectDefinition's HasAssociations returns a set of IIfcRelAssociates but you want just the derived type IIfcRelAssociatesMaterial which has the RelatingMaterial property. See https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2/HTML/schema/ifcproductextension/lexical/ifcrelassociatesmaterial.htm

So, it's just a matter of adding .OfType<IIfcRelAssociatesMaterial> to constrain the query to Material associations. i.e.

var materials = theWall.HasAssociations.OfType<IIfcRelAssociatesMaterial>() 
// rest of the query

推荐阅读