ifcopenshell.util.schema

Module Contents

class ifcopenshell.util.schema.BatchReassignClass(file: ifcopenshell.file)
purge() None
reassign(element: ifcopenshell.entity_instance, new_class: str) ifcopenshell.entity_instance
unbatch()
file
class ifcopenshell.util.schema.Migrator
find_equivalent_attribute(new_element: ifcopenshell.entity_instance, attribute: ifcopenshell.ifcopenshell_wrapper.attribute, element: ifcopenshell.entity_instance, attributes_mapping: dict[str, dict[str, str]], reverse_mapping: bool = False) Any | None
generate_default_value(attribute: ifcopenshell.ifcopenshell_wrapper.attribute, new_file: ifcopenshell.file) Any
migrate(element: ifcopenshell.entity_instance, new_file: ifcopenshell.file) ifcopenshell.entity_instance
migrate_attribute(attribute: ifcopenshell.ifcopenshell_wrapper.attribute, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file, new_element: ifcopenshell.entity_instance, new_element_schema: ifcopenshell.ifcopenshell_wrapper.declaration) None
migrate_attributes(element: ifcopenshell.entity_instance, new_file: ifcopenshell.file, new_element: ifcopenshell.entity_instance, new_element_schema: ifcopenshell.ifcopenshell_wrapper.declaration) ifcopenshell.entity_instance
migrate_class(element: ifcopenshell.entity_instance, new_file: ifcopenshell.file) ifcopenshell.entity_instance
preprocess(old_file: ifcopenshell.file, new_file: ifcopenshell.file) None
attribute_overrides: dict[int, dict[int, str]]
attributes_mapping
class_2x3_to_4
class_4_to_2x3
default_entities
default_values
migrated_ids: dict[int, int]
ifcopenshell.util.schema.get_declaration(element: ifcopenshell.entity_instance)

Get the schema declaration of an actively used entity instance

IFC models are made out of instances (e.g. with a STEP ID) of entities (e.g. IfcWall). Those entities are defined through a Schema Declaration.

Schema Declaration objects can be used to query information about the IFC schema itself, such as data types, enumeration values, and inheritance.

Parameters:

element – Any instance, typically from a loaded or created IFC model

Example:

wall = model.createIfcWall()
declaration = ifcopenshell.util.schema.get_declaration(wall)
print(declaration.name()) # IfcWall
print(declaration.is_abstract()) # False
print(declaration.supertype().name()) # IfcBuildingElement
ifcopenshell.util.schema.get_fallback_schema(version: str) str

fallback to the schema version we do have docs and mapping for, needed to support IFC versions like 4X3_RC1, 4X1 etc

ifcopenshell.util.schema.get_subtypes(declaration: ifcopenshell.ifcopenshell_wrapper.entity) list[ifcopenshell.ifcopenshell_wrapper.entity]

Get a flat list of subtype declarations

Abstract classes are skipped.

Inconsistently, the declaration itself is also added to this list. This should be fixed exclude the declaration itself.

Parameters:

declaration – The declaration from the schema, as an entity.

Returns:

A list of subtypes in order from child to grandchild.

schema = ifcopenshell.schema_by_name("IFC4")
declaration = schema.declaration_by_name("IfcFlowSegment")
print(ifcopenshell.util.schema.get_subtypes(declaration))
[<entity IfcFlowSegment>, <entity IfcCableCarrierSegment>, ..., <entity IfcPipeSegment>]
ifcopenshell.util.schema.get_supertypes(declaration: ifcopenshell.ifcopenshell_wrapper.entity) list[ifcopenshell.ifcopenshell_wrapper.entity]

Gets a list of supertype declarations

Parameters:

declaration – The declaration from the schema, as an entity.

Returns:

A list of supertypes in order from parent to grandparent.

Example:

wall = model.createIfcWall()
results = ifcopenshell.util.schema.get_supertypes(wall.wrapped_data.declaration().as_entity())
# [<entity IfcBuildingElement>, <entity IfcElement>, ..., <entity IfcRoot>]
ifcopenshell.util.schema.is_a(declaration: ifcopenshell.ifcopenshell_wrapper.entity, ifc_class: str) bool

Checks if a schema declaration is a class

Parameters:
  • declaration – The declaration from the schema.

  • ifc_class – A case insensitive IFC class name (e.g. IfcRoot)

Returns:

True is the declaration is of that class

Example:

wall = model.createIfcWall()
declaration = ifcopenshell.util.schema.get_declaration(wall)
ifcopenshell.util.schema.is_a(declaration, "IfcRoot") # True
ifcopenshell.util.schema.reassign_class(ifc_file: ifcopenshell.file, element: ifcopenshell.entity_instance, new_class: str) ifcopenshell.entity_instance

Attempts to change the class (entity name) of element to new_class by removing element and recreating a similar instance of type new_class with the same id.

In certain cases it may affect the structure of inversely related instances: - Multiple occurrences of reassigned instance within the same aggregate

(such as start and end-point of polyline)

  • Occurrences of reassigned instance within an ordered aggregate (such as IfcRelNests)

It’s unlikely that this affects real-world usage of this function.

ifcopenshell.util.schema.IFC_SCHEMA
ifcopenshell.util.schema.cwd