ifcpatch.recipes.Migrate

Module Contents

class ifcpatch.recipes.Migrate.Patcher(file: ifcopenshell.file, logger: logging.Logger | None = None, schema: ifcopenshell.util.schema.IFC_SCHEMA = 'IFC4')

Bases: ifcpatch.BasePatcher

Migrate from one IFC version to another.

The recipe iterates every entity in the source file and rewrites it into a new file with the target schema, delegating per-entity class / attribute translation to ifcopenshell.util.schema.Migrator. Upgrades (IFC2X3 → IFC4, IFC4 → IFC4X3) are best supported because the target schema is a superset; downgrades are lossy by definition (see below). Entities that fail to migrate are collected; on completion a summary RuntimeError is raised listing up to 20 failures.

IFC4 → IFC2X3 downgrade additionally runs a preprocessing pipeline so IFC4-only geometry and element classes survive the schema gap:

  • IfcIndexedPolyCurve (including arc segments, approximated by a chord polyline) is flattened to IfcPolyline.

  • IfcPolygonalFaceSet and IfcTriangulatedFaceSet are converted directly to IfcFacetedBrep at the entity level, preserving the original mesh topology.

  • Orphan IFC4-only geometry instances left over after the rewires are purged so the migration loop does not trip on them.

  • IFC4-only IfcElement subclasses (IfcLamp, IfcPipeSegment, IfcGeographicElement, …) fall back to IfcBuildingElementProxy via the Migrator’s fallback_element_to_proxy opt-in. The original class and PredefinedType are encoded into ObjectType (e.g. "IfcLamp/COMPACTFLUORESCENT") when ObjectType is empty, so the type information survives the downgrade.

Non-element IFC4-only entities (relationships, geometry items outside any product, …) that have no direct equivalent still raise NotImplementedError from the Migrator with the failing class and inverse references named, instead of the cryptic Entity with name '' not found in schema 'IFC2X3'.

Parameters:

schema – The schema identifier of the IFC version to migrate to.

Example:

# Upgrade an IFC2X3 model to IFC4
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "Migrate", "arguments": ["IFC4"]})
patch()
schema = 'IFC4'