ifcopenshell.entity_instance#

Module Contents#

ifcopenshell.entity_instance._method_dict#
ifcopenshell.entity_instance.logging#
ifcopenshell.entity_instance.schema#
class ifcopenshell.entity_instance.entity_instance(e, file=None)#

Bases: object

Base class for all IFC objects.

An instantiated entity_instance will have methods of Python and the IFC class itself.

Example:

ifc_file = ifcopenshell.open(file_path)
products = ifc_file.by_type("IfcProduct")
print(products[0].__class__)
>>> <class 'ifcopenshell.entity_instance.entity_instance'>
print(products[0].Representation)
>>> #423=IfcProductDefinitionShape($,$,(#409,#421))
__dict__#
__ge__#
__gt__#
__le__#
__lt__#
__rge__#
__rgt__#
__rle__#
__rlt__#
__del__(self)#

#2471 while the precise chain of action is unclear, creating instance references prevents file gc, even with all instance refs deleted. This is a work-around for that.

__dir__(self)#

Default dir() implementation.

__eq__(self, other)#

Return self==value.

__getattr__(self, name)#
__getitem__(self, key)#
__hash__(self)#

Return hash(self).

__len__(self)#
__repr__(self)#

Return repr(self).

__setattr__(self, key, value)#

Implement setattr(self, name, value).

__setitem__(self, idx, value)#
attribute_name(self, attr_idx)#

Return the name of a positional attribute of the element

Parameters

attr_idx (int) – The index of the attribute

Return type

string

attribute_type(self, attr)#

Return the data type of a positional attribute of the element

Parameters

attr (int) – The index of the attribute

Return type

string

compare(self, 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

property file(self)#
get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False)#

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(self, 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(self)#

Return the STEP numerical identifier

Return type

int

is_a(self, *args)#

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 (string) – If specified, is a case insensitive IFC class name to check

Returns

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

Return type

string|bool

Example:

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

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(self, valid_spf=True)#

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, g, value)#
static wrap_value(v, file)#
ifcopenshell.entity_instance.register_schema_attributes(schema)#
ifcopenshell.entity_instance.set_derived_attribute(*args)#
ifcopenshell.entity_instance.set_unsupported_attribute(*args)#