ifcopenshell

Welcome to IfcOpenShell! IfcOpenShell provides a way to read and write IFCs.

IfcOpenShell can open IFC files, read entities (such as walls, buildings, properties, systems, etc), edit attributes, write out .ifc files and more.

This module provides primitive functions to interact with IFC, including:

  • For most users, you can open and read IFC models, see docs for open(). This returns an file object representing the IFC model. You can then query the model to filter elements.

  • For developers, you can query the schema itself, see docs for schema_by_name(). This returns a schema object which you can use to analyse the definitions of IFC classes and data types.

You may also be interested in:

For more details, consult https://docs.ifcopenshell.org/

Example:

import ifcopenshell

print(ifcopenshell.version)

model = ifcopenshell.open("/path/to/model.ifc")
walls = model.by_type("IfcWall")

for wall in walls:
    print(wall.Name)

Subpackages

Submodules

Package Contents

class ifcopenshell.entity_instance(*args)

Bases: ifcopenshell.entity_instance.entity_instance_mixin

Represents an entity (wall, slab, property, etc) of an IFC model

An IFC model consists of entities. Examples of entities include walls, slabs, doors and so on. Entities can also be non-physical things, like properties, systems, construction tasks, colours, geometry, and more.

Entities are defined through an IFC Class. There are hundreds of IFC Classes defined as part of the ISO standard by the buildingSMART International organisation. The IFC Class defines the attributes of an entity, as well as the data types and whether or not an attribute is mandatory or optional.

IfcOpenShell’s API dynamically implements the IFC schema. You will not find documentation about available IFC Classes, or what attributes they have. Please consult the buildingSMART official documentation or start reading Introduction to IFC.

In addition to the Python methods you see documented here, an instantiated entity_instance will have attributes defined by its IFC class. For example, an entity instance which is an IfcWall class will have a Name attribute, and an IfcColourRgb will have a Red attribute. Please consult the buildingSMART official documentation.

Example:

model = ifcopenshell.open(file_path)
walls = model.by_type("IfcWall")
wall = walls[0]

print(wall) # #38=IFCWALL('2MEinnTPbCMwLOgceaQZFu',$,$,'My Wall',$,#52,#47,$,$);
print(wall.is_a()) # IfcWall

# Note: the `Name` attribute is dynamic, based on the IFC class.
print(wall.Name) # My Wall

# Attributes are ordered and may also be accessed via index.
print(wall[3]) # My Wall

print(wall.__class__) # <class 'ifcopenshell.entity_instance'>
attribute_name(i: int) → str
attribute_type(*args: int | str) → Literal['NULL', 'DERIVED', 'INT', 'BOOL', 'LOGICAL', 'DOUBLE', 'STRING', 'BINARY', 'ENUMERATION', 'ENTITY INSTANCE', 'EMPTY AGGREGATE', 'AGGREGATE OF INT', 'AGGREGATE OF DOUBLE', 'AGGREGATE OF STRING', 'AGGREGATE OF BINARY', 'AGGREGATE OF ENTITY INSTANCE', 'AGGREGATE OF EMPTY AGGREGATE', 'AGGREGATE OF AGGREGATE OF INT', 'AGGREGATE OF AGGREGATE OF DOUBLE', 'AGGREGATE OF AGGREGATE OF ENTITY INSTANCE', 'UNKNOWN']
file_pointer() → int
get_argument(*args: int | str) → Any
get_argument_index(a: str) → int
get_attribute_category(name: str) → Literal[0, 1, 2, 3]

Get attribute category id.

Available categories: - 0 - invalid attribute - 1 - forward attribute - 2 - inverse attributes - 3 - derived attribute

get_attribute_names() → tuple[str, ...]
get_attribute_value(attribute_index: int) → Any
get_inverse_attribute_names() → tuple[str, ...]
id() → int
identity() → int

Entity instance identity, unique across all opened IFC files during current session.

is_a(*args)
set_attribute_value(*args)
set_attribute_value_py(i: int, value: Any) → None
to_string(*args) → str | None
unset_attribute_value(attribute_index: int) → None
property declaration: declaration
property file: ifcopenshell.file
class ifcopenshell.file(schema: ifcopenshell.util.schema.IFC_SCHEMA | None = None, schema_identifier: str | None = None, schema_version: tuple[int, int, int, int] | None = None)

Bases: ifcopenshell.file.file_mixin

Base class for containing IFC files.

Class has instance methods for filtering by element Id, Type, etc. Instantiated objects can be subscripted by Id or Guid

Example:

model = ifcopenshell.open(file_path)
products = model.by_type("IfcProduct")
print(products[0].id(), products[0].GlobalId) # 122 2XQ$n5SLP5MBLyL442paFx
print(products[0] == model[122] == model["2XQ$n5SLP5MBLyL442paFx"]) # True
add_type_ref(new_entity)
by_guid(global_id: str) → entity_instance
by_id(instance_id: int) → entity_instance
bypass_type(type_name: str) → None

Skip loading instances of type_name.

create(*args) → entity_instance
static create_timestamp() → str
static create_uninitialized(logger: file.create_uninitialized.logger | None = None) → file

Construct a file with no schema/data yet, to be populated by a later call to initialize().

When file is uninitialized, the only two available methods during this state are bypass_type() and initialize().

entity_names() → tuple[int, ...]

Get a tuple of step ids present in the file.

file_pointer() → int
fresh_id() → int
static from_string(s: str) → file
get_inverse_indices_by_id(instance_id: int) → tuple[int, ...]
get_inverses_by_declaration(instance_id: int, declaration: file.get_inverses_by_declaration.declaration, attribute_index: int) → tuple[entity_instance, ...]

Get instance inverses of the particular type defined by declaration.

Parameters:
  • declaration – Type of inverses to find. Supertypes are also supported - e.g. ‘IfcRoot’ will also include all ‘IfcRelationship’ inverses.

  • attribute_index – Find references only from the provided attribute index. Could be set to -1 to consider all attributes.

get_max_id() → int
get_total_inverses(*args: entity_instance | int) → int
good() → file_open_status
ifcroot_type() → entity
initialize(*args: str) → bool

Parse a file on a create_uninitialized() instance.

Parameters:

args – args[0] is a string path to the IFC file.

Returns:

Whether the file was read and parsed successfully. On failure, check good() for the specific reason.

key_value_store_iter(prefix)
key_value_store_query(key)
lazy_loading(*args: bool) → bool

Get, or with an argument set, whether initialize() indexes the file with one pass and parses each instance’s attributes on first access. Set before initialize().

paged_reading(*args: bool) → bool

Get, or with an argument set, whether initialize() reads the file through the paged reader instead of loading it whole. Set before initialize().

recalculate_id_counter()
remove_type_ref(new_entity)
reset_identity_cache()
storage_mode()
to_string()
types() → tuple[str, ...]

Return a tuple of classes present in the file.

E.g. (“IfcWallType”, “IfcWall”, “IfcArbitraryClosedProfileDef”, …).

property header: spf_header
property schema_identifier: str
class ifcopenshell.sqlite(filepath: str)

Bases: ifcopenshell.file

Open existing sqlite IFC database.

To create a new database from IFC file consider using Ifc2Sql IfcPatch:

https://docs.ifcopenshell.org/autoapi/ifcpatch/recipes/Ifc2Sql/index.html

Parameters:

filepath – Path to sqlite database.

by_id(id: int) → sqlite_entity | None
by_type(type: str, include_subtypes: bool = True) → list[sqlite_entity]
clear_cache() → None
create_entity(type, *args, **kawrgs) → NoReturn

Not supported for sqlite database.

get_geometry(ids: list[int]) → GeometryCache
get_inverse(inst: sqlite_entity, allow_duplicate: bool = False, with_attribute_indices: bool = False) → set[sqlite_entity]
is_entity_list(attribute: ifcopenshell.ifcopenshell_wrapper.attribute) → bool
preprocess_schema() → None
traverse(inst: sqlite_entity, max_levels: int | None = None, breadth_first: bool = False) → list[sqlite_entity]
class_map: dict[str, list[int]]
cursor
db
entity_cache: dict[int, sqlite_entity]
filepath
future = []
property header: types.SimpleNamespace
history = []
history_size = 64
id_map: dict[int, str]
ifc_schema
instance_map: dict[str, ifcopenshell.entity_instance]
mvd_str: str

As in header.file_description.description.

property schema: ifcopenshell.util.schema.IFC_SCHEMA
property schema_identifier: str
shadow_file
state = [[], [], None]
transaction = None
property wrapped_data: NoReturn
class ifcopenshell.sqlite_entity(id: int, ifc_class: str, file: sqlite = None)
get_info(include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False) → dict[str, Any]
id() → int
is_a(*args)
unserialise_value(value)
property file: sqlite
sqlite_wrapper: sqlite_entity.sqlite_wrapper
wrapped_data: ifcopenshell.entity_instance
ifcopenshell.clear_plugin_search_paths() → None
ifcopenshell.get_plugin_search_paths() → tuple[str, ...]
ifcopenshell.set_plugin_search_paths(paths: collections.abc.Sequence[os.PathLike | str]) → None
ifcopenshell.decode_spf_string
ifcopenshell.encode_spf_string
ifcopenshell.rocksdb_lazy_instance