IFCPatch tool now available

I problem I usually face is that IFCs exported from proprietary applications have various issues in them. I want to fix them, but most IFC authoring programs do an import-export process that results in a huge amount of data being lost in-between.

To solve this, I usually run a quick Python script which uses IfcOpenShell to modify the IFC file. However this is usually something only I can do but others cannot do in the office. For this reason I made IFCPatch.

Basically, it's a CLI app which you can feed in an IFC file, and apply a "recipe" which will modify the IFC in some predefined manner. For example:

$ ifcpatch -i foo.ifc -r ResetAbsoluteCoordinates

This will detect any IfcCartesianPoint which are placed in absolute coordinates (i.e. very far away) and correct them - which is a common problem in incorrectly geolocated IFCs produced from 12D.

Recipes can also allow arguments to be passed, such as:

$ ifcpatch -i foo.ifc -r OffsetStoreyLocations -a 1000

That will shift up all building stories by 1000 units.

I hope its useful to someone. Being a CLI app, I have integrated it into a Git hook when consultants submit their files.

bitacovirJesusbilledwinguerraberndCGREloyRD

Comments

  • How do I run IfcPatch? If I compile and install latest IfcOpenShell I only have "IfcConvert" and "IfcGeomServer" binaries starting with "Ifc" installed?

    Do you have an exapmple for IfcPatch and ExtractElements ?

  • @bernd IfcPatch is pure Python. See link in first post.

    Example:

    $ ifcpatch -i foo.ifc -o out.ifc -r ExtractElements -a ".IfcWall"
    
  • ok
    In your example you did call ifcpatch out of your bash, but ifcpatch is a directory in ifcopenshell sources. How should I call ifcpatch if there is no python module ifcpatch? There is only a package (directory) named ifcpatch in ifcopenshell sources.

    I seam to miss the forest because of the trees ...

  • Ah ifcpatch used to be a standalone .py file which symlinked in my /usr/local/bin to give that behaviour... now it's a module, so, uh :) Times change!

  • than there where just clouds in front of the forest :-) Again the sun is shining ... Got it. Thanks

    Moult
  • So i have a big IFC from Tekla which is too big and creating problems in Revit. @Moult thought that IfcPatch could be a solution since what I want to do is split the file so there is one file per building. It's a huge steel structure for two buildings in one file. Dion is rather busy at the moment @bernd do you have time to help me understand how to do something like this?

  • edited February 25

    @duncan : I missed the post ...
    I will give it a try ... hoepfully you are on Linux ...

    read this first ... https://github.com/IfcOpenShell/IfcOpenShell/blob/3eacd809b0dc0c4d03d4675f3f64a509cb27789f/src/ifcpatch/README.md

    Set up you system

    # clone ifcopenshell
    # start Python 3, on most Linux machines this is done by "python3" ATM
    the_path_of_ifcpatch = "/the/path/to/ifcopenshell/which/you/have/cloned/into/src/ifcpatch/"  # change this for your needs
    import sys
    sys.path.append(the_path_of_ifcpatch)
    import ifcpatch 
    import lark  # you will need this, I had to insall it by "pip3 install lark" because Debian Buster does not have lark packages
    # if there was no error you are ready ...
    

    get some ifc data to play with ... https://github.com/buildingSMART/Sample-Test-Files/tree/master/IFC 2x3/Schependomlaan/Design model IFC

    Run ifcpatch:

    • cd in the directory where the Schependomlaan ifc is saved
    • start python by python3
    • copy the following code
    import sys
    sys.path.append("/home/hugo/Documents/dev/ifcopenshell/ifcopenshell-official/ifcos/src/ifcpatch/")  # change this for your needs
    import ifcpatch
    
    ifcpatch.execute({
        "input": "IFC Schependomlaan.ifc",
        "output": "IFC Schependomlaan_OnlyWalls.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": [".IfcWall"],
    })
    
  • Moult this is AWESOME * AWESOME

  • edited February 25

    some more examples ... the query taken from here
    https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples#IFC_Query_Syntax

    import sys
    sys.path.append("/home/hugo/Documents/dev/ifcopenshell/ifcopenshell-official/ifcos/src/ifcpatch/")
    import ifcpatch
    
    ifcpatch.execute({
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
        "output": "/home/hugo/NeuOrd/IFC Schependomlaan_AllWalls.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": [".IfcWall"],
    })
    
    ifcpatch.execute({
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
        "output": "/home/hugo/NeuOrd/IFC Schependomlaan_AllSabsWalls.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": [".IfcWall | .IfcSlab"],
    })
    
    ifcpatch.execute({
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
        "output": "/home/hugo/NeuOrd/IFC Schependomlaan_StoreyElements.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": ["@ #0u4wgLe6n0ABVaiXyikbkA"],
    })
    
    ifcpatch.execute({
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
        "output": "/home/hugo/NeuOrd/IFC Schependomlaan_WallsComplexWithOpenings.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": ["#0BbZBldn94MfvyeV9ZExMT | #1HB2RkFMD9UQq5pmmS3kII"],
    })
    
    
    ifcpatch.execute({
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
        "output": "/home/hugo/NeuOrd/IFC Schependomlaan_WallsSimple.ifc",
        "recipe": "ExtractElements",
        "log": "ifcpatch.log",
        "arguments": ["#0GkhpndB96r98q9Zpfg0ks| #2kHoPrvTH4mgO72z01pDOc"],
    })
    
  • I am looking to test this IFCPatch out. I was wondering if we can patch any property within an IFC File? Particularly in my case is the IFCGUID. Maintaining IFCGUID has been a problem for various modeling platforms and I am looking for a way to keep that a constant even if it mean replacing it again with a baseline reference. Any ideas?

Sign In or Register to comment.