Example: Wall Volume Calculation
An example of the power of MyBimApi.
This page shows two examples of how to calculate quantities in IFC: analyzing the raw geometry or looking up pre-calculated properties.
The reason we show this example is to highlight the flexibility of MyBimApi. It also shows how you can fine-tune the structure of the response to your needs.
Method 1: Calculation from Geometry
This method uses the ifcopenshell.geom engine to create an explicit
shape from the wall's definitions and calculates the exact volume. It is accurate but
computationally more expensive.
import ifcopenshell
from ifcopenshell.geom import *
from ifcopenshell.util.shape import *
def run(ifc : ifcopenshell.file):
def volume(elem):
# Calculate from geometry
shp = create_shape(settings(), elem)
return get_volume(shp.geometry)
return sum(map(volume, ifc.by_type('IfcWall')))
Method 2: Property Lookup
This method relies on the data (Property Sets) attached to the element. It is very fast but depends on the quality of the data in the model (e.g., if the volume was exported correctly).
import ifcopenshell
from ifcopenshell.util.element import *
def run(ifc : ifcopenshell.file):
def volume(el):
# Look-up property value
for di in get_psets(el).values():
for k, v in di.items():
if k.lower() == "volume":
return v
return 0
# Sum up volumes found in properties
return sum(volume(w) for w in ifc.by_type('IfcWall'))
Looking for more examples?
We offer a wide range of example Python scripts in the editor's 'Samples' dropdown menu on your Dashboard.
Use them as a base to fine-tune your own BIM analysis logic.
Ready to Start Building?
Turn your Python scripts into scalable BIM APIs today. No credit card required. Get 100 free credits to get started.
Create Your First BIM API