XbimWindowsUI icon indicating copy to clipboard operation
XbimWindowsUI copied to clipboard

Read wall physical dimensions.

Open joselaks opened this issue 5 years ago • 3 comments

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 !

joselaks avatar May 15 '20 17:05 joselaks

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

andyward avatar May 18 '20 09:05 andyward

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é

joselaks avatar May 19 '20 20:05 joselaks

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

CBenghi avatar May 20 '20 14:05 CBenghi