API Documentation

class ifcopenshell.entity_instance.entity_instance(e)

This is the base Python 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))
attribute_name(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(attr)

Return the data type of a positional attribute of the element

Parameters

attr (int) – The index of the attribute

Return type

string

get_info(include_identifier=True, recursive=False, return_type=<class 'dict'>, ignore=())

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

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'])
id()

Return the STEP numerical identifier

Return type

int

is_a(*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
class ifcopenshell.file.file(f=None, schema=None)

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:

ifc_file = ifcopenshell.open(file_path)
products = ifc_file.by_type("IfcProduct")
print(products[0].id(), products[0].GlobalId)
>>> 122 2XQ$n5SLP5MBLyL442paFx
# Subscripting
print(products[0] == ifc_file[122] == ifc_file['2XQ$n5SLP5MBLyL442paFx'])
>>> True
add(inst)

Adds an entity including any dependent entities to an IFC file.

If the entity already exists, it is not re-added.

by_guid(guid)

Return an IFC entity instance filtered by IFC GUID.

Parameters

guid (string) – GlobalId value in 22-character encoded form

Returns

An ifcopenshell.entity_instance.entity_instance

Return type

ifcopenshell.entity_instance.entity_instance

by_id(id)

Return an IFC entity instance filtered by IFC ID.

Parameters

id (int) – STEP numerical identifier

Returns

An ifcopenshell.entity_instance.entity_instance

Return type

ifcopenshell.entity_instance.entity_instance

by_type(type, include_subtypes=True)

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

Returns

A list of ifcopenshell.entity_instance.entity_instance objects

Return type

list

create_entity(type, *args, **kwargs)

Create a new IFC entity in the file.

Parameters
  • type (string) – Case insensitive name of the IFC class

  • args – The positional arguments of the IFC class

  • kwargs – The keyword arguments of the IFC class

Returns

An entity instance

Return type

ifcopenshell.entity_instance.entity_instance

Example:

f = ifcopenshell.file()
f.create_entity('IfcPerson')
>>> #1=IfcPerson($,$,$,$,$,$,$,$)
f.create_entity('IfcPerson', 'Foobar')
>>> #2=IfcPerson('Foobar',$,$,$,$,$,$,$)
f.create_entity('IfcPerson', Identification='Foobar')
>>> #3=IfcPerson('Foobar',$,$,$,$,$,$,$)
get_inverse(inst)

Return a list of entities that reference this entity

Parameters

inst (ifcopenshell.entity_instance.entity_instance) – The entity instance to get inverse relationships

Returns

A list of ifcopenshell.entity_instance.entity_instance objects

Return type

list

remove(inst)

Deletes an IFC object in the file.

Attribute values in other entity instances that reference the deleted object will be set to null. In the case of a list or set of references, the reference to the deleted will be removed from the aggregate.

Parameters

inst (ifcopenshell.entity_instance.entity_instance) – The entity instance to delete

Return type

None

traverse(inst, max_levels=None)

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

Parameters
Returns

A list of ifcopenshell.entity_instance.entity_instance objects

Return type

list

exception ifcopenshell.validate.ValidationError
class ifcopenshell.validate.log_entry_type(level, message, instance)
property instance

Alias for field number 2

property level

Alias for field number 0

property message

Alias for field number 1

class ifcopenshell.ids.BcfHandler(project_name='IDS Project', author='your@email.com', filepath=None, report_valid=False)

Logging handler for creation of BCF report files.

Parameters
  • project_name (str, optional) – defaults to “IDS Project”

  • author (str, optional) – Email of the person creating the BCF report, defaults to “your@email.com

  • filepath (str, optional) – Path to save the BCF report, defaults to None

  • report_valid (bool, optional) – True if you want to list all the compliant cases as well, defaults to False

Example:

bcf_handler = BcfHandler(
    project_name="Default IDS Project",
    author="your@email.com",
    filepath=r".\example.bcfzip",
)
logger = logging.getLogger("IDS_Logger")
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger.addHandler(bcf_handler)
emit(log_content)

Triggered on each use of logging with the BCF handler enabled.

Parameters

log_content (string|dict) – default logger message

flush()

Saves the BCF report to file. Triggered at the end of the validation process.

class ifcopenshell.ids.SimpleHandler(report_valid=False)

Logging handler listing all cases in python list.

emit(mymsg)

Triggered on each use of logging with the Simple handler enabled.

Parameters

log_content (string|dict) – default logger message

class ifcopenshell.ids.boolean_and(terms)
fold()

Return True if bool(x) is True for all values x in the iterable.

If the iterable is empty, return True.

class ifcopenshell.ids.boolean_logic(terms)

Boolean conjunction over a collection of functions

class ifcopenshell.ids.boolean_or(terms)
fold()

Return True if bool(x) is True for any x in the iterable.

If the iterable is empty, return False.

class ifcopenshell.ids.classification(node=None, location=None)

The IDS classification facet by traversing the HasAssociations inverse attribute

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static create(location='any', value=None, system=None)

Create a classification facet that can be added to applicability or requirements of IDS specification.

Parameters
  • location (str, optional) – Define where to check for the parameter. One of “any”|”instance”|”type”, defaults to “any”

  • value (restriction|alphanumeric, optional) – Value that is required. Could be alphanumeric or restriction object, defaults to None

  • system (restriction|alphanumeric, optional) – System that is required. Could be alphanumeric or restriction object, defaults to None

Returns

classification object

Return type

classification

class ifcopenshell.ids.entity(node=None, location=None)

The IDS entity facet currently with inheritance

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static create(name=None, predefinedtype=None)

Create an entity facet that can be added to applicability or requirements of IDS specification.

Parameters
  • name (str, optional) – IFC entity name that is required. e.g. IfcWall, defaults to None

  • predefinedtype (str, optional) – name of the predefined type, defaults to None

Returns

entity object

Return type

entity

class ifcopenshell.ids.facet(node=None, location=None)

The base class for IDS facets. IDS facets are functors constructed from XML nodes that return True or False. A getattr method is provided for conveniently extracting XML child node text content. Use child classes instead: entity, classification, property and material.

class ifcopenshell.ids.facet_evaluation(success, str)

The evaluation of a facet with data from IFC. Converts to bool and has a human readable string format.

class ifcopenshell.ids.ids(ifcversion=None, description=None, author=None, copyright=None, version=None, creation_date=None, purpose=None, milestone=None)

Represents the XML root <ids> node and its <specification> childNodes.

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static open(filepath, ids_schema=XMLSchema10(name='ids.xsd', namespace='http://standards.buildingsmart.org/IDS'))

Use to open ids.xml files

Parameters
  • filepath (str) – ids file path

  • ids_schema (XMLschema, optional) – XML Schema for an IDS file, defaults to ids_schema object from buildingSMART

Returns

IDS file as a python object

Return type

ids object

to_xml(filepath='./', ids_schema=XMLSchema10(name='ids.xsd', namespace='http://standards.buildingsmart.org/IDS'))

Save IDS object as .xml file.

Parameters
  • filepath (str, optional) – Path for the new file, defaults to “./”

  • ids_schema (XMLschema, optional) – XML Schema for an IDS file, defaults to ids_schema object from buildingSMART

Returns

Result of the newly created file validation against the schema.

Return type

bool

validate(ifc_file, logger=None)

Use to validate IFC model against IDS specifications.

Parameters
  • ifc_file (str) – path to ifc file

  • logger (logging, optional) – Logging object with handlers, defaults to None

class ifcopenshell.ids.material(node=None, location=None)

The IDS material facet used to traverse the HasAssociations inverse attribute.

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static create(location='any', value=None)

Create a material facet that can be added to applicability or requirements of IDS specification.

Parameters
  • location (str, optional) – Define where to check for the parameter. One of “any”|”instance”|”type”, defaults to “any”

  • value (restriction|alphanumeric, optional) – Value that is required. Could be alphanumeric or restriction object, defaults to None

Returns

material object

Return type

material

class ifcopenshell.ids.meta_facet(clsname, bases, attrs)

A metaclass for automatically registering facets in a map to be instantiated based on XML tagnames.

ifcopenshell.ids.parameter_asdict(parameter)

Converts parameter to an IDS compliant dictionary, handling both value and restrictions.

Returns

Xmlschema compliant dictionary.

Return type

dict

class ifcopenshell.ids.property(node=None, location=None)

The IDS property facet implemented using ifcopenshell.util.element

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static create(location='any', propertyset=None, name=None, value=None)

Create a property facet that can be added to applicability or requirements of IDS specification.

Parameters
  • location (str, optional) – Define where to check for the parameter. One of “any”|”instance”|”type”, defaults to “any”

  • propertyset (restriction|alphanumeric, optional) – Propertyset that is required. Could be alphanumeric or restriction object, defaults to None

  • name (restriction|alphanumeric, optional) – Name that is required. Could be alphanumeric or restriction object, defaults to None

  • value (restriction|alphanumeric, optional) – Value that is required. Could be alphanumeric or restriction object, defaults to None

Returns

property object

Return type

property

class ifcopenshell.ids.restriction

The value restriction from XSD implemented as a list of values and a containment test

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static create(options, type='pattern', base='string')

Create restriction instead of simpleValue

Parameters
  • type (str, optional) – One of “enumeration”|”pattern”|”bounds”, defaults to “pattern”

  • options (list|str|dict) – if enumeration: list of possible values if pattern: xml regular expression string if bounds: dictionary with possible keys: ‘minInclusive’, ‘maxInclusive’, ‘minExclusive’, ‘maxExclusive’

  • base (str, optional) – One of “string”|”boolean”|”decimal”|”integer”, defaults to “string”

Raises

Exception – If not properly defined restriction.

Returns

restriction object

Return type

restriction

static parse(ids_dict)

Parse xml restriction to python object.

Parameters

ids_dict (dict) –

class ifcopenshell.ids.specification(name='Specification', necessity='required')

Represents the XML <specification> node and its two children <applicability> and <requirements>

add_applicability(facet)

Applicability specifies what conditions must be meet for an IFC object to be used for validation. Note, that at least one entity facet is required.

Parameters

facet (facet) – any of entity|classification|property|material

Example:

i = ids.ids()
i.specifications.append(ids.specification(name="Test_Specification"))
e = ids.entity.create(name="Test_Name", predefinedtype="Test_PredefinedType")
i.specifications[0].add_applicability(e)
add_requirement(facet)

Requirement is validated on all applicable IFC elements. Note, that at least one facet of any type is required.

Parameters

facet (facet) – any of entity|classification|property|material

asdict()

Converts object to a dictionary, adding required attributes.

Returns

Xmlschema compliant dictionary.

Return type

dict

static parse(ids_dict)

Parse xml specification to python object.

Parameters

ids_dict (dict) –