title: Extracting quantities of elements with IfcOpenShell in python
body: <p>I am trying to read the deepest level of quantities for objects in an <code>ifc</code> file, using <code>IfcOpenShell</code> in Python. So far I have:</p>
  
  <pre><code>import ifcopenshell
  
  path = r'D:\ifcos_1\slab.ifc'
  ifc_file = ifcopenshell.open(path)
  
  geometries = ifc_file.by_type("IfcProduct")
  
  for geometry in geometries:
      if geometry.is_a("IfcSlab"):
          print geometry
          test = geometry.IfcPhysicalQuantity()
          print test
  </code></pre>
  
  <p>I've studied the <a href="http://www.buildingsmart-tech.org/ifc/IFC4/final/html/index.htm" rel="nofollow noreferrer">definitions</a></p>
  
  <p>No matter which type of function I try to place for the <code>test = geometry.X()</code>, I get an error:</p>
  
  <blockquote>
  <pre><code>File "C:\Python27\lib\site-packages\ifcopenshell\entity_instance.py", line 48, in __getattr__
     "entity instance of type '%s' has no attribute '%s'" % (self.wrapped_data.is_a(), name))
  AttributeError: entity instance of type 'IfcSlab' has no attribute 'IfcPhysicalQuantity'
  </code></pre>
  </blockquote>
  
  <p>Not sure how to solve this and would appreciate help.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Further work which gets the slab and further references:</p>
  
  <pre><code>for geometry in geometries:
      if geometry.is_a("IfcSlab"):
          print geometry
          definedBy = geometry.IsDefinedBy
  
          print definedBy[0]
  
          for each in definedBy:
              test = each.is_a()
              print test
  </code></pre>
  
  <p>As of this moment the obstacle is the compatibility with IFC4, which I will try to recompile with instructions from <a href="https://sourceforge.net/p/ifcopenshell/discussion/1782717/thread/870bb6b6/" rel="nofollow noreferrer">this forum post.</a></p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Further work using for now the IFC 2x3 standard, with a file that has quantity information (verified via the raw data). The following is the relevant code:</p>
  
  <pre><code>for geometry in geometries:
      if geometry.is_a("IfcSlab"):
          definedBy = geometry.IsDefinedBy
  
          for line in definedBy:
          test = line.is_a()
          # print test
          if line.is_a() == 'IfcRelDefinesByProperties' or line.is_a() == 'IfcRelDefinesByType':
              step1 = line.RelatingPropertyDefinition
              step2 = step1.is_a()
              print step2
  </code></pre>
  
  <p>There is an error no matter what I place after <code>step1 = line.</code>, none of the following give a result:</p>
  
  <pre><code>line.IfcPropertySet
  line.IfcElementQuantity
  line.RelatingPropertyDefiniton
  </code></pre>
  
  <p>The output from this code is nevertheless:</p>
  
  <pre><code>IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcPropertySet
  IfcElementQuantity
  IfcElementQuantity
  </code></pre>
  
  <p>Which means that I can access <code>IfcElementQuantity</code> but none of the Attributes work. I've looked at <a href="http://www.buildingsmart-tech.org/ifc/IFC4/Add2TC1/html/link/ifcreldefinesbyproperties.htm" rel="nofollow noreferrer">schema reference</a> but can't find the correct one.</p>