简体   繁体   中英

How to get the material data of specific IfcElement

In the basic operations in the xbim examples https://docs.xbim.net/examples/basic-model-operations.html , it shows how to retrieve the single value properties of a specific IfcElement. Based on this I've tried to get the material data.

I've written the following:

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>();

It gives me this error:

'IIfcRelAssociates' does not contain a definition for 'RelatingMaterial' and no accessible extension method 'RelatingMaterial' accepting a first argument of type 'IIfcRelAssociates' could be found (are you missing a using directive or an assembly reference?)

I understand that I have to use the IfcRelAssociatesMaterial, but I can't figure how. How can I retrieve the material information?

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. ie

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

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