ifcopenshell.entity_instance

Module Contents

class ifcopenshell.entity_instance.entity_instance(e, file=None)

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(attr_idx: int) str

Return the name of a positional attribute of the element

Parameters:

attr_idx (int) – The index of the attribute

Return type:

string

attribute_type(attr: int | str) str

Return the data type of a positional attribute of the element

Parameters:

attr (Union[int, str]) – The index or name of the attribute

Return type:

string

compare(other, op, reverse=False)

Compares with another instance.

For simple types the declaration name is not taken into account:

>>> f = ifcopenshell.file()
>>> f.createIfcInteger(0) < f.createIfcPositiveInteger(1)
True

For entity types the declaration name is taken into account:

>>> f.createIfcWall('a') < f.createIfcWall('b')
True
>>> f.createIfcWallStandardCase('a') < f.createIfcWall('b')
False

Comparing simple types with different underlying types throws an exception:

>>> f.createIfcInteger(0) < f.createIfcLabel('x')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "entity_instance.py", line 371, in compare
    return op(a, b)
TypeError: '<' not supported between instances of 'int' and 'str'
Args:

other (_type_): Right hand side (or lhs when reverse = True) op (_type_): The comparison operator (likely from the operator module) reverse (bool, optional): When true swaps lhs and rhs. Defaults to False.

Returns:

bool: The comparison predicate applied to self and other

get_info(include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False) dict

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

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

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

  • return_type (dict|list|other) – The return data type to be casted into

  • ignore (set|list) – A list of attribute names to ignore

  • scalar_only (bool) – Filters out all values that are IFC instances

Returns:

A dictionary of properties and their corresponding values

Return type:

dict

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'])
get_info_2(include_identifier=True, recursive=False, return_type=dict, ignore=())

More perfomant version of .get_info() but with limited arguments values.

Method has exactly the same signature as .get_info() but it doesn’t support getting information non-recursively.

Currently supported arguments values:
  • include_identifier: True

  • recursive: True (will fail with default False value from .get_info())

  • return_type: dict

  • ignore: () (empty tuple)

id() int

Return the STEP numerical identifier

Return type:

int

is_a() str
is_a(ifc_class: str) bool
is_a(with_schema: bool) str

Return the IFC class name of an instance, or checks if an instance belongs to a class.

The check will also return true if a parent class name is provided.

Parameters:

args (Union[str, bool]) – If specified, is a case insensitive IFC class name to check or if specified as a boolean then will define whether returned IFC class name should include schema name (e.g. “IFC4.IfcWall” if True and “IfcWall” if False). If omitted will act as False.

Returns:

Either the name of the class, or a boolean if it passes the check

Return type:

Union[str, bool]

Example:

f = ifcopenshell.file()
f.create_entity('IfcPerson')
f.is_a()
>>> 'IfcPerson'
f.is_a('IfcPerson')
>>> True
is_entity() bool

Tests whether the instance is an entity type as opposed to a simple data type.

Returns:

bool: True if the instance is an entity

to_string(valid_spf=True) str

Returns a string representation of the current entity instance. Equal to str(self) when valid_spf=False. When valid_spf is True returns a representation of the string that conforms to valid Step Physical File notation. The difference being entity names in upper case and string attribute values with unicode values encoded per the specific control directives.

static unwrap_value(v)
static walk(f: Callable[[Any], bool], g: Callable[[Any], Any], value: Any) Any

Applies a transformation to value based on a given condition.

If value is a nested structure (e.g., a list or a tuple) will apply transformation to it’s elements.

Parameters:
  • f (Callable) – A callable that takes a single argument and returns a boolean value. It represents the condition.

  • g (Callable) – A callable that takes a single argument and returns a transformed value. It represents the transformation.

  • value (Any) – Any object, the input value to be processed

Returns:

Transformed value

Return type:

Any

Example:

# Define condition and transformation functions
condition = lambda v: v == old
transform = lambda v: new

# Usage example
attribute_value = element.RelatedElements
print(old in attribute_value, new in attribute_value) # True, False

result = element.walk(condition, transform, element.RelatedElements)
print(old in attribute_value, new in attribute_value) # False, True
static wrap_value(v, file)
property file
wrapped_data: ifcopenshell.ifcopenshell_wrapper.entity_instance
ifcopenshell.entity_instance.register_schema_attributes(schema: ifcopenshell.ifcopenshell_wrapper.schema_definition) None
ifcopenshell.entity_instance.set_derived_attribute(*args)
ifcopenshell.entity_instance.set_unsupported_attribute(*args)
ifcopenshell.entity_instance.T
ifcopenshell.entity_instance.logging
ifcopenshell.entity_instance.schema