ifcopenshell.sql

Module Contents

class ifcopenshell.sql.sqlite(filepath: str)

Bases: ifcopenshell.file.file

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

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

Return an IFC entity instance filtered by IFC ID.

Parameters:

id (int) – STEP numerical identifier

Raises:

RuntimeError – If id is not found.

Returns:

An ifcopenshell.entity_instance

Return type:

ifcopenshell.entity_instance

by_type(type: str, include_subtypes: bool = True) list[sqlite_entity]

Return IFC objects filtered by IFC Type and wrapped with the entity_instance class.

If an IFC type class has subclasses, all entities of those subclasses are also returned.

Parameters:
  • type (string) – The case insensitive type of IFC class to return.

  • include_subtypes (bool) – Whether or not to return subtypes of the IFC class

Raises:

RuntimeError – If type is not found in IFC schema.

Returns:

A list of ifcopenshell.entity_instance objects

Return type:

list[ifcopenshell.entity_instance]

clear_cache() None
create_entity(type, *args, **kawrgs) NoReturn

Not supported for sqlite database.

get_geometry(ids: list[int]) dict[str, dict]
get_inverse(inst: sqlite_entity, allow_duplicate: bool = False, with_attribute_indices: bool = False) set[sqlite_entity]

Return a list of entities that reference this entity

Warning: this is a slow function, especially when there is a large number of inverses (such as for a shared owner history). If you are only interested in the total number of inverses (typically 0, 1, or N), consider using get_total_inverses().

Parameters:
  • inst – The entity instance to get inverse relationships

  • allow_duplicate – Returns a list when True, set when False

  • with_attribute_indices – Returns pairs of <i, idx> where i[idx] is inst or contains inst. Requires allow_duplicate=True

Returns:

A list or set of ifcopenshell.entity_instance objects.

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]

Get a list of all referenced instances for a particular instance including itself

Parameters:
  • inst – The entity instance to get all sub instances

  • max_levels – How far deep to recursively fetch sub instances. None or -1 means infinite.

  • breadth_first – Whether to use breadth-first search, the default is depth-first.

Returns:

A list of ifcopenshell.entity_instance objects

class_map: dict[str, list[int]]
cursor
db
entity_cache: dict[int, sqlite_entity]
filepath
future = []
history = []
history_size = 64
id_map: dict[int, str]
ifc_schema
schema: ifcopenshell.util.schema.IFC_SCHEMA = 'IFC4'

General IFC schema version: IFC2X3, IFC4, IFC4X3.

transaction = None
wrapped_data = None
class ifcopenshell.sql.sqlite_entity(id: int, ifc_class: str, file: sqlite = None)

Bases: ifcopenshell.entity_instance.entity_instance

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'>
get_info(include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False) dict[str, Any]

Return a dictionary of the entity_instance’s properties (Python and IFC) and their values.

Parameters:
  • include_identifier – Whether or not to include the STEP numerical identifier

  • recursive – Whether or not to convert referenced IFC elements into dictionaries too. All attributes also apply recursively

  • return_type – The return data type to be casted into

  • ignore – A list of attribute names to ignore

  • scalar_only – Filters out all values that are IFC instances

Returns:

A dictionary of properties and their corresponding values

Example:

ifc_file = ifcopenshell.open(file_path)
products = ifc_file.by_type("IfcProduct")
obj_info = products[0].get_info()
print(obj_info.keys())
>>> dict_keys(['Description', 'Name', 'BuildingAddress', 'LongName', 'GlobalId', 'ObjectPlacement', 'OwnerHistory', 'ObjectType',
>>> ...'ElevationOfTerrain', 'CompositionType', 'id', 'Representation', 'type', 'ElevationOfRefHeight'])
id() int

Return the STEP numerical identifier

Return type:

int

unserialise_value(value)
sqlite_wrapper: sqlite_entity.sqlite_wrapper
class ifcopenshell.sql.sqlite_wrapper(id: int, ifc_class: str, file: sqlite)
attribute_cache: dict[str, Any]
attributes
file
id
ifc_class
inverse_attribute_cache
inverse_attributes