IfcOpenShell
IfcOpenShell is an open-source (LGPL) software library providing an API for working with the Industry Foundation Classes (IFC) data model, used in Building Information Modeling (BIM). The `ifcopenshell` Python library offers high-level bindings and utilities for reading, writing, and manipulating IFC files. It is currently at version 0.8.5 and receives updates aligning with the underlying C++ library, with an irregular release cadence.
Common errors
-
ModuleNotFoundError: No module named 'ifcopenshell'
cause The ifcopenshell package was not installed or is not accessible in the current Python environment.fixRun `pip install ifcopenshell` in the correct virtual environment. Ensure your Python version is compatible with the latest IfcOpenShell release. -
ImportError: DLL load failed while importing _ifcopenshell: The specified module could not be found.
cause This usually indicates missing underlying C++ dependencies (e.g., Visual C++ Redistributables on Windows), or that a compatible binary wheel (`ifcopenshell-python`) could not be installed for your specific platform/Python version.fixOn Windows, install the latest Visual C++ Redistributables. Ensure your Python version matches a pre-built wheel available for your OS and architecture. Check `pip debug` output for more clues or consider using a different Python environment. -
TypeError: guid.create_guid() takes 0 positional arguments but 1 was given
cause Attempting to use the deprecated `create_guid()` function with an argument, or using it at all in v0.8+ where it's been replaced.fixReplace `ifcopenshell.create_guid()` with `ifcopenshell.guid.new()` which generates a new GUID without arguments. -
TypeError: argument of type 'IfcProduct' is not iterable
cause You are trying to iterate over a single IFC entity object, likely returned by `ifc_file.by_id()` or if a `by_type()` call only returned one result, without properly converting it to a list if iteration is intended.fixIf `by_id()` is used, it returns a single object. If `by_type()` might return one, convert to a list: `my_entities = list(ifc_file.by_type('IfcWall'))` or check `if isinstance(entity, list):` before iterating.
Warnings
- breaking Major API changes occurred between v0.7 and v0.8, particularly in geometry processing and file creation. Code written for v0.7 will likely break in v0.8.
- gotcha IfcOpenShell has strict Python version requirements and platform-specific binary wheels. Installation might fail if your Python version or operating system/architecture is not supported by a pre-built wheel.
- deprecated The `ifcopenshell.file.createIfcFile()` function is effectively superseded by `ifcopenshell.template()`, which offers a more robust and flexible way to create new IFC files.
Install
-
pip install ifcopenshell
Imports
- ifcopenshell
import ifcopenshell
- open
from ifcopenshell import open
ifcopenshell.open(...)
- template
ifcopenshell.template(...)
- guid.new
ifcopenshell.create_guid()
ifcopenshell.guid.new()
- geom.settings
settings = ifcopenshell.geom.settings()
Quickstart
import ifcopenshell
import os
# Create a new IFC4 file
ifc_file = ifcopenshell.template(schema="IFC4")
# Create a project entity
project_guid = ifcopenshell.guid.new()
project = ifc_file.create_entity("IfcProject", project_guid)
project.Name = "My First IfcOpenShell Project"
# Add the project to the file
ifc_file.add(project)
# Define output path
output_path = "my_first_project.ifc"
# Save the IFC file
ifc_file.write(output_path)
print(f"Successfully created IFC file: {output_path}")
# Optional: Clean up the created file for repeated runs
if os.path.exists(output_path):
os.remove(output_path)
print(f"Cleaned up {output_path}")