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(*, fallback_element_to_proxy: bool = False)

Construct a schema migrator.

Parameters:

fallback_element_to_proxy – When True and the target schema is IFC2X3, IFC4 entity classes that have no direct IFC2X3 equivalent but inherit from IfcElement / IfcElementType are migrated as IfcBuildingElementProxy / IfcBuildingElementProxyType respectively, instead of raising. Caller code is then responsible for preserving the lost original class information out-of-band (the Migrate ifcpatch recipe encodes it into ObjectType). Defaults to False so non-recipe callers keep the strict failure-on-unmappable contract.

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
fallback_element_to_proxy = False
migrated_ids: dict[int, int]
ifcopenshell.util.schema.geometry_classes_introduced_after(target_schema: IFC_SCHEMA, source_schema: IFC_SCHEMA = 'IFC4') → frozenset[str]

IfcRepresentationItem subclasses present in source_schema but missing in target_schema.

Derived from the loaded schema declarations once per (source, target) pair and cached. The result is the canonical set of geometry classes a downgrade from source_schema to target_schema must convert (IfcPolygonalFaceSet, IfcTriangulatedFaceSet, IfcAdvancedBrep, B-splines, advanced surfaces, alignment curves on IFC4X3 → 2X3, …) or purge. Defaults match the IFC4 → IFC2X3 case for backwards compatibility with the original caller.

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) → IFC_SCHEMA

Fallback to the schema version we do have docs and mapping for.

Needed to support IFC versions like 4X3_RC1, 4X1 etc.

Parameters:

version – Typically a string from ifcopenshell.file.schema_identifier, e.g. IFC4X3_ADD2

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

Get a flat list of subtype declarations, recursively.

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.declaration.as_entity())
# [<entity IfcBuildingElement>, <entity IfcElement>, ..., <entity IfcRoot>]
ifcopenshell.util.schema.ifc4_only_geometry_classes() → frozenset[str]

Backwards-compatible alias for the IFC4 → IFC2X3 geometry-gap set.

New code should call geometry_classes_introduced_after() with the explicit (target, source) pair so IFC4X3 → IFC2X3 downgrades pick up the additional IFC4X3-only geometry classes.

ifcopenshell.util.schema.is_a(declaration: ifcopenshell.ifcopenshell_wrapper.declaration, 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 | None, 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.

Raises:

ValueError – If new_class does not exist in the provided file schema.

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