IfcOpenShell find coordinates from IfcWall

1k views Asked by At

I would like to find the length between two points from an IFC model.This is an example of an IfcWall from the IFC model.

#26322= IFCWALL('3vpWoB_K1EZ8RCaYmNGsB2',#42,'Basiswand:Bestand 08.0:162343',$,'Basiswand:Bestand 08.0:161894',#25861,#26318,'162343',.NOTDEFINED.); 
#26325= IFCPROPERTYSET('3vpWoB_K1EZ8RCcT4NGsB2',#42,'Pset_WallCommon',$,(#787,#788,#848,#25851));
#26327= IFCRELDEFINESBYPROPERTIES('0rDc6OePf5NBrNT2GfJ3hm',#42,$,$,(#26322),#26325);
#26331= IFCCARTESIANPOINT((12.5832056790716,5.54096330043285,0.));
#26333= IFCAXIS2PLACEMENT3D(#26331,#20,#18);
#26334= IFCLOCALPLACEMENT(#140,#26333);
#26335= IFCCARTESIANPOINT((4.24,0.));
#26337= IFCPOLYLINE((#10,#26335));
#26339= IFCSHAPEREPRESENTATION(#102,'Axis','Curve2D',(#26337));

The IFCPOLYLINE has two Points (#10=0,0 and #26335=4.24,0.) and i would like to find out the distance between these two points.

The other walls have a length deposited, but this one wall does not. Here is an example of the other walls:

#730= IFCWALL('1ZwJH$85D3YQG5AK5ER10a',#42,'Basiswand:Bestand 50.0:148105',$,'Basiswand:Bestand 50.0:150882',#701,#726,'148105',.NOTDEFINED.);
#745= IFCQUANTITYLENGTH('Height',$,$,4.99,$);
#746= IFCQUANTITYLENGTH('Length',$,$,16.675,$);

This is my code example:

import ifcopenshell
walls = ifc_file.by_type('IfcWall')
print(len(walls))

import math

p1 = [0.,0.]
p2 = [16.765,0.]
distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )
print(distance)

To apply the mathematical formula, I have to extract the coordinates from the wall for p1 and p2. I am not getting further here.

thank you in advance!

1

There are 1 answers

0
hlg On

You need to work your way through the object graph, starting at the wall:

#26322 IfcWall.Representation (attribute 7) references #26318
#26318 is not included in your snippet, but likely an IfcProductDefinitionShape

From there you would likely find another polyline similar to the one you have included in the snippet. See below for how to get there. There is likely another wall which is represented by the polyline #25337. Starting from there you arrive at the polyline as follows:

#XXXXX IfcWall.Representation (attribute 7) references #YYYYY likely IfcProductDefinitionShape
#YYYYY IfcProductDefinitionShape.Representations (attribute 4) likely references #26339 (the 2D representation) and a 3D representation
#26339 IfcShapeRepresentation.Items (attribute 4) references #26337
#25337 IfcPolyline.Points (attribute 1) references #10 and #26335

You can study the IFC specification to find out how the entities are connected via their attributes and how the attributes are called.

It might be easy for a this particular case to trace the object graph. The hard part is the semantic richness of the schema with a variety of types which share some attributes and vary in others, which is organized through inheritance. For example, the Item attribute of an IfcShapeRepresentation entity references entities of type IfcRepresentationItem, which has many subtypes, IfcPolyline being only one of those. You will have to check which type you encounter and only if it is an IfcPolyline, your method of calculation would be applicable - not if it would be an IfcBSplineCurve, for example.

Libraries such as IfcOpenShell have invested a good deal of work into covering all or at least most of the schema, particularly the geometry, and can also calculate measures such as length, area, volume, if I am not mistaken.