Files
IfcOpenShell/src/ifcpatch
Gorgious56 f710929e9e ifcpatch Migrate: defensive IFC4/IFC4X3 -> IFC2X3 downgrade
The Migrate recipe previously crashed mid-loop with the cryptic
`RuntimeError: Entity with name '' not found in schema 'IFC2X3'` when
asked to downgrade an IFC4 or IFC4X3 file to IFC2X3 — the
class_4_to_2x3 mapping marks IFC4-only geometry / element classes with
an empty-string sentinel and the old code blindly forwarded that to
create_entity. Real files routinely contain IfcPolygonalFaceSet,
IfcTriangulatedFaceSet, IfcIndexedPolyCurve, IfcLamp, IfcPipeSegment,
IfcGeographicElement, etc.

The recipe now runs a preprocessing pipeline when the target is IFC2X3
and the source is IFC4 or IFC4X3:

- DowngradeIndexedPolyCurve flattens IfcIndexedPolyCurve to IfcPolyline
  for the whole file (arcs included — see below).
- IfcPolygonalFaceSet / IfcTriangulatedFaceSet are converted directly
  to IfcFacetedBrep at the entity level via
  ifcopenshell.util.shape_builder.polygonal_face_set_to_faceted_brep,
  preserving topology including IfcIndexedPolygonalFaceWithVoids inner
  bounds. IfcShapeRepresentation carriers have their RepresentationType
  tag updated from "Tessellation" to "Brep".
- Orphan source-only geometry instances (left over after the rewires)
  are purged iteratively via
  geometry_classes_introduced_after(target, source).

The Migrator is invoked with fallback_element_to_proxy=True so
IFC4-only IfcElement subclasses (IfcLamp, IfcPipeSegment,
IfcGeographicElement, ...) become IfcBuildingElementProxy in the
output. A post-pass encodes "<OriginalClass>/<PredefinedType>" into
ObjectType (e.g. "IfcLamp/COMPACTFLUORESCENT") when ObjectType is
empty, so the lost subclass identity survives the downgrade as
searchable text.

The migration loop now collects per-entity failures into a list rather
than crashing on the first; a summary RuntimeError fires at end if any
failed, naming up to 20 with their inverse references. Successful
migrations log a single count line via self.logger.

DowngradeIndexedPolyCurve extended:
- Arc segments (IfcArcIndex) are flattened via
  ifcopenshell.util.shape_builder.arc_to_polyline_points with
  ARC_SUBDIVISION=16 chord points per arc.
- Multi-index IfcLineIndex segments handled correctly.
- Absent Segments list (IFC4 polyline-through-all-coords case) handled.

Test coverage: 11 tests across the two recipes covering all four
preprocessing branches, the IFC4X3 source gate, the ObjectType
encoding (incl. author-supplied ObjectType preservation), the summary
RuntimeError shape, and the arc subdivision.

Generated with the assistance of an AI coding tool.
2026-06-23 09:33:03 +02:00
..
2026-01-26 17:10:03 +05:00
2024-06-27 11:49:12 +10:00

IfcPatch

Utility for applying modification recipes to IFC files. IfcPatch enables programmatic editing and correction of IFC models through a collection of patches that can fix common issues, migrate data, or transform models.

Available Recipes

Alignment and Linear Placement

  • AddGeometricRepresentationToAlignment - Add geometric representations to alignment elements
  • AddLinearPlacementFallbackPosition - Add fallback positions for linear placements
  • AddZeroLengthSegmentToAlignment - Add zero-length segments to alignments
  • PatchStationReferentPosition - Patch station referent positions

Data Conversion and Migration

  • AGS2IFC - Convert AGS (geotechnical) data to IFC
  • ConvertLengthUnit - Convert between length units
  • ConvertNestToAggregate - Convert nesting relationships to aggregations
  • ConvertPropertiesToQuantities - Convert properties to quantities
  • Migrate - Migrate between IFC schema versions

Element Extraction and Manipulation

  • ExtractElements - Extract specific elements into a new model
  • ExtractPropertiesToSQLite - Export properties to SQLite database
  • Ifc2Sql - Convert IFC to SQL database
  • TessellateElements - Tessellate elements into triangulated geometry

Fixing Software-Specific Issues

  • FixArchiCADToRevitDoorSwings - Fix door swing orientation from ArchiCAD for Revit
  • FixArchiCADToRevitSpaces - Fix space data from ArchiCAD for Revit
  • FixRevit2025TINs - Fix TIN (Triangulated Irregular Network) issues from Revit 2025
  • FixRevitClassificationCodeTypes - Fix classification code data types from Revit
  • FixRevitTINs - Fix TIN issues from Revit

Geometry and Representation

  • AssignConstituentFractions - Assign fractions to material constituents
  • DowngradeIndexedPolyCurve - Convert indexed poly curves to simpler representations
  • RemoveSiteRepresentation - Remove geometric representation from site elements

Merging and Optimization

  • MergeDuplicateTypes - Merge duplicate element types
  • MergeProjects - Merge multiple IFC projects
  • MergeStyles - Merge duplicate styles
  • Optimise - Optimize file size and structure
  • PurgeData - Remove unused data from model

Spatial and Coordinate Systems

  • OffsetObjectPlacements - Offset object placement coordinates
  • OffsetStoreyElevations - Offset storey elevations
  • ResetAbsoluteCoordinates - Reset absolute coordinates to origin
  • ResetSpatialElementLocations - Reset spatial element locations
  • SetFalseOrigin - Set a false origin for coordinates
  • SetRefElevation - Set reference elevation
  • SetWorldCoordinateSystem - Set world coordinate system
  • SplitByBuildingStorey - Split model by building storeys

Utilities

  • RecycleNonRootedElements - Remove or recycle non-rooted elements
  • RegenerateGlobalIds - Regenerate GlobalId values for elements
  • RemoveRevitUniformatClassification - Remove Revit Uniformat classification
  • UnsharePsets - Unshare property sets between elements