Code

Reading a simple quantity from an IFC file

Use IfcOpenShell to read a quantity already stored on an element — and to detect when the file has no quantity set at all. Geometry-derived takeoff is a different problem.

IFC can carry quantities that someone already stored on an element (IfcElementQuantity / Qto property sets). That is not the same as computing a takeoff from geometry, and it is not a substitute for a bill of quantities signed in the office. This tutorial reads what is in the file, converts length-related values with the project unit, and fails loudly when the quantity is missing.

Do not paste EXPRESS schema or copyrighted buildingSMART tables into a notebook. Use the library and the schema documentation at the source.

Detect first

IfcOpenShell is an independent open-source project. Install it in your environment. This site does not bundle it.

def require_ifcopenshell():
    try:
        import ifcopenshell
        import ifcopenshell.util.element as element_util
        import ifcopenshell.util.unit as unit_util
    except ImportError as exc:
        raise SystemExit(
            "IfcOpenShell is not importable in this interpreter. "
            "Install ifcopenshell in the same environment you use for BIM scripts. "
            "This tutorial does not bundle IFC tooling."
        ) from exc
    return ifcopenshell, element_util, unit_util

Prerequisites

  • Python 3 and IfcOpenShell importable (detect step)
  • An IFC file you exported (this article does not ship a model)
  • The unit-conversion habit: a raw IFC real is not “metres” until you apply the project unit

What “a simple quantity” means here

We read quantities attached through the usual IFC relationships and exposed by ifcopenshell.util.element.get_psets(..., qtos_only=True). Typical names you may see on IFC4 exports include sets such as beam base quantities — if the exporter wrote them. Many files have empty Qto maps. That is a valid outcome, not a library bug.

We do not:

  • triangulate the body and integrate volume as “the” quantity
  • copy classification tables or schema excerpts
  • invent a volume when the Qto is absent

Implementation

Pass the path on the command line. Print the length scale to SI metres, then list each IfcBeam (fall back to IfcWall if the file has no beams) with its quantity sets.

import sys

ifcopenshell, element_util, unit_util = require_ifcopenshell()

if len(sys.argv) < 2:
    raise SystemExit("usage: python read_qto.py path/to/model.ifc")

path = sys.argv[1]
model = ifcopenshell.open(path)

length_to_si = unit_util.calculate_unit_scale(model)
print(f"project length unit → metres, scale = {length_to_si}")

products = model.by_type("IfcBeam") or model.by_type("IfcWall")
if not products:
    raise SystemExit("no IfcBeam or IfcWall in this file")

missing_qto = 0
for product in products[:20]:
    name = product.Name or "(unnamed)"
    gid = product.GlobalId
    qtos = element_util.get_psets(product, qtos_only=True) or {}
    print(f"{gid}  {name}")
    if not qtos:
        missing_qto += 1
        print("  (no quantity sets)")
        continue
    for qset_name, values in qtos.items():
        print(f"  {qset_name}:")
        for key, raw in values.items():
            if key == "id":
                continue
            print(f"    {key} = {raw!r}")

print(f"elements inspected = {min(len(products), 20)}")
print(f"elements with no Qto = {missing_qto}")

If you need a length in metres and the value is stored as a project-length real, multiply by length_to_si. Area and volume need the scale to the second and third power. Applying the length scale once to a volume is a unit bug — same family as mixing mm and m in a beam script.

get_psets also returns property sets that are not quantities. This script asks for qtos_only=True so you do not treat an IfcPropertySingleValue named like a quantity as a Qto.

Validation

  1. Run the script on a file you know has Qto (your own export with quantities enabled) and on a file that does not. The second run should report missing Qto, not a fabricated number.
  2. Check calculate_unit_scale against the project length unit you set in the authoring tool (metres versus millimetres is the usual fork). If the tool said millimetres and the scale is not 1e-3, stop and inspect IfcUnitAssignment.
  3. Pick one element. Compare the printed volume or length to the same quantity in the native BIM UI. If they disagree, believe neither blindly: exporters remap names, drop Qto, or store geometry-derived values under a different set.
  4. Confirm you did not multiply a volume by length_to_si only once. A mismatch of 1e3 or 1e9 is almost always the exponent on the unit scale.

Common mistakes

  • Assuming every IFC4 file has Qto_*BaseQuantities. Many coordination models omit them.
  • Treating NetVolume from software A as comparable to GrossVolume from software B without reading both names.
  • Using geometry bounding-box volume as a stand-in when Qto is missing, then labeling it as an IFC quantity.
  • Opening the file with a different IfcOpenShell than the one you tested — schema helpers change between major versions.

Limitations

  • This is a read of stored quantities. It is not a takeoff engine, not a cost cascade, and not a claim that the IFC quantity matches construction measurement rules.
  • Units for area and volume must follow the project unit dimensions. Some files mix SI length with non-SI area; inspect units rather than assuming a single scale.
  • Element types, Qto names, and IFC2x3 versus IFC4 differences are larger than this page. Official schema documentation is at buildingSMART. Do not scrape copyrighted schema text into the article.
  • ifcopenshell.open must receive a path you are allowed to read. This tutorial does not download models.

Professional context

A quantity in IFC is evidence of what the exporter wrote, not of what was built. For contractual measurement, the governing rules, the measurement method, and the signed register sit outside the file. Use this script to see the payload, then validate against the native model and the office procedure.

References

  • IfcOpenShell documentation and util.element / util.unit helpers. https://docs.ifcopenshell.org/
  • buildingSMART International. IFC schema and quantity-set documentation (read at the source; do not reproduce tables here).
  • Unit scale pitfalls: the companion tutorial unit-conversion-pitfalls-civil-scripts.