New IfcOpenShell utility to convert between IFC2X3 and IFC4

To my knowledge, there is no robust conversion utility available in both the proprietary and FOSS worlds that do IFC2X3<->IFC4. You could theoretically pass it through an authoring app, but that's a data loss nightmare for proprietary apps, and tools like the BlenderBIM Add-on aren't there yet, though they are much closer. With a utility like this, apart from the obvious usecase of upgrading / downgrading for compatibility, it can also help in partial data exchange and IFC-roundtripping, which is underway in the BlenderBIM Add-on.

I've started an attempt here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/schema.py

It's still incomplete, and it works through a two step process. The first step attempts to convert the IFC class. The second step attempts to convert the attributes in the IFC class. I expect this tool to mature over time and turn into a robust utility.

The class mapping is derived from the IFC4 changelog. However, a human needs to go through and make a decision on how to map classes, or if they can even be mapped. buildingSMART does not seem to have any documents regarding this. E.g. IfcExternalSpatialElement - should we discard it, or can we gracefully downgrade to IfcSpace? More complex mappings are also not yet supported, like polygonal face sets vs faceted breps.

The attribute mapping is also derived from the IFC4 changelog. However, sometimes things aren't so straightforward. E.g. if both a class mapping and an attribute mapping applies, there is no official document which describes the migration path. I think we'll just come across these from experience over time.

duncanCyrilberndbitacovirJanFDADA_universecarlopav

Comments

  • Sorry to resurrect :) Can you describe a bit how to use this? If I understand right, the process should be:

    • Create a new, empty IFC file with the wished schema
    • Create an instance of ifcopenshell.util.schema.Migrator()
    • Use Migrator.migrate with each ifc entity from the old file

    This only works between IFC2x3 and IFC4 at the moment, right?
    I guess it's better to use ifcPatch, like BBIM does, but it would be interesting for me to stay with pure IfcOpenShell

  • Indeed, the steps are very simple and only a few lines of code: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcpatch/ifcpatch/recipes/Migrate.py#L46-L49 - though sooner or later you might want to bundle IfcPatch as it has a lot of tricks up its sleeve :)

    It only works with IFC2X3<->IFC4 right now (though for large projects, IFC2X3->IFC4 is significantly more robust compared to IFC4->IFC2X3). It's pretty easy to tweak to adjust it to support more schemas though.

  • Oh yes, it's really simple :) Thanks!
    Yes, there is much more to ifcopenshell that we'll need sooner or later I guess (ifcpatch, ifcdiff...) but I'd rather not have to copy those files over for now, to avoid possible forking

  • I'm having trouble downgrading from IFC4 to IFC2x3. I understand it's not really supported but I would like for it to work :)

      File "...\lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 5846, in new_IfcBaseClass
        return _ifcopenshell_wrapper.new_IfcBaseClass(schema_identifier, name)
    RuntimeError: Entity with name 'IfcPolygonalFaceSet' not found in schema 'IFC2X3'
    

    I take it polygonal face sets are not supported in 2x3, is there a way for me to batch convert my meshes to a supported format, or is it too much trouble and I should rather start from scratch in 2x3 ? I Tried the Tesselate patch but to no avail.

  • @Gorgious said:
    I take it polygonal face sets are not supported in 2x3, is there a way for me to batch convert my meshes to a supported format, or is it too much trouble and I should rather start from scratch in 2x3 ? I Tried the Tesselate patch but to no avail.

    Sure, you can convert them using bpy.ops.bim.update_representation(ifc_representation_class="IfcTessellatedFaceSet")

    But need to make sure you have forced faceted breps enabled otherwise it will use facesets in >=ifc4.

    I've also added option to force faceted breps in TessellateElements patch (available after commit).

    Gorgious
  • Thank you, that was it ! Now I know what these settings do :) The file size has more than doubled, but oh well, at least it loads in Revit :) And the file size is still half of the .rvt file ><

    Cheers !

Sign In or Register to comment.