introduction
there are a few models from which I need to extract properties and quantities, like when I link multiple ones in a federated arrangement
if it was for one model only I would use Spreadsheet Import/Export
combining multiple models requires some script
thankfully ChatGPT helped me out in putting this together, so if any programming bad style it's its fault..
modules/functions used:
import modules and
- Load IFC models into a list of dictionaries
import ifcopenshell
from ifcopenshell.util.selector import filter_elements
from ifccsv import IfcCsv
import os
def load_model_list(model_paths: list[str]) -> list[dict]:
return [
{
"model": ifcopenshell.open(path),
"name": os.path.splitext(os.path.basename(path))[0],
"path": path
}
for path in model_paths
]
- Export filtered elements from a model to a CSV in the same folder
def export_model_to_csv(model, model_name: str, model_path: str, query: str, attributes: list[str]) -> None:
elements = filter_elements(model, query)
if not elements:
print(f"⚠️ No matching elements in model '{model_name}'")
return
model_dir = os.path.dirname(model_path)
output_file = os.path.join(model_dir, f"{model_name}_extract.csv")
ifc_csv = IfcCsv()
ifc_csv.export(
model,
elements,
attributes,
output=output_file,
format="csv",
delimiter=",",
null="-"
)
print(f"✅ Exported model '{model_name}' to:\n {output_file}")
- Main function
change model_paths, query, and attributes to your need
in this example query and attributes select all IfcWall
elements with type starting with "WAL-"
from selected elements extracts attributes like Name
, type.Name
, and NetSideArea
before running the script make sure that original models have quantity take-off already done
def main():
model_paths = [
r"path to ifc file\filename1.ifc",
r"path to ifc file\filename2.ifc"
]
query = 'IfcWall, type=/WAL-.*/'
attributes = ["Name", "type.Name", "Qto_WallBaseQuantities.NetSideArea"]
models = load_model_list(model_paths)
print("\n📂 Loaded Models:")
for m in models:
print(f"- {m['name']}: {m['path']}")
for m in models:
export_model_to_csv(
model=m["model"],
model_name=m["name"],
model_path=m["path"],
query=query,
attributes=attributes
)
- Run the script
if __name__ == "__main__":
main()
Code attached
I would hugely appreciate your feedback, thanks