xBimTeam / XbimWindowsUI

The home of XbimXplorer and WPF components for your desktop BIM applications.
Other
248 stars 149 forks source link

Read wall physical dimensions. #150

Open joselaks opened 4 years ago

joselaks commented 4 years ago

I am very enthusiastic about xBIM! I am trying to make a code that reads the walls and obtains from each one of them the physical dimensions (surface, volume, etc). I got here but cannot include code that reads it inside the "foreach" ... how do I do it?

using (var model = IfcStore.Open(filename))
{
    var allWalls = model.Instances.OfType<IIfcWall>();
    foreach (var item in allWalls)
    {
        //Read the surface, volume, etc....
    }
}

Thank you !

andyward commented 4 years ago

Hi Jose,

you want something like:

using Xbim.Ifc4.Interfaces;

using (var model = IfcStore.Open(filename))
{
  var allWalls = model.Instances.OfType<IIfcWall>(); // All items of type IIfcWall
  foreach (var item in allWalls)
  {
  //Read the surface, volume, etc....
  }
}

But be sure to take a look at https://docs.xbim.net/examples/using-linq-for-optimal-performance.html

joselaks commented 4 years ago

Hi Andy Thanks for the reply! To find out the length and width of the walls I use this code. Is there something more efficient?

using (var model = IfcStore.Open(filename))
{
    var allWalls = model.Instances.OfType(); // All items of type IIfcWall
    foreach (var item in allWalls)
    {
        var longitudes = item.IsDefinedBy
            .SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions)
            .OfType()
            .SelectMany(qset => qset.Quantities)
            .OfType();
        if (longitudes.Count() != 0)
        {
            var ancho = longitudes.FirstOrDefault(a => a.Name == "Width");
            var alto = longitudes.FirstOrDefault(a => a.Name == "Height");
        }
    }
}

Best Regards, José

CBenghi commented 4 years ago

Hello @joselaks, you will find that different models store the information that you are looking for in inconsistent ways, it's better to have a look at a bunch of models before you use any code similar to this in production. Otherwise this seems to work. Best, Claudio