OSArch Community

IFCPatch tool now available

  1. M

    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.

  2. B

    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 ?

  3. M

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

    Example:

    
    $ ifcpatch -i foo.ifc -o out.ifc -r ExtractElements -a ".IfcWall"
    
  4. B

    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 ...

  5. M

    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!

  6. B

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

  7. D

    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?

  8. B

    @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%202x3/Schependomlaan/Design%20model%20IFC

    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"],
    
    })
    
  9. B

  10. B

    Moult this is AWESOME * AWESOME

  11. B

    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"],
    
    })
    
  12. T

    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?

  13. M

    For a bit of clarification, IfcPatch is simply a way to distribute a script that modifies an IFC in some way. It is up to you to write the script yourself, or use one from a collection of recipes provided with IfcPatch. If you're after modifying a particular property, it's best to write your own script. Alternatively, if scripting is not your thing, IfcCSV is a great way to pull out particular properties, modify them, then import the changes back in.

  14. E

    @Moult to clarify: I thought from a previous post that attributes , such as Global ID, could not be modified using IfcCSV, is this accurate?

  15. M

    @edwinguerra you should be able to edit attribute, except for GlobalId. The reason the GlobalId cannot be edited is because it is used as the unique linking key.

  16. B

    Currently, IFCPatch works with very simple recipes.

    Will it be able to run more complex algorithms that contain many recipes? Something similar to OpenStudio measures?

    Hmm, it would be nice to have a library of IFC measures.

  17. B
  18. L

    Can someone tell me what

    https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/ifcpatch/ifcpatch/recipes/SplitByBuildingStorey.py

    does? creates an ifc for each Storey? Depending where the one ifc-object is classified to?

    sorry found: https://community.osarch.org/discussion/comment/1150/#Comment_1150

    What when the ifc-building is messed up with elements that range over several floors. Or a declared Groundfloor-element appears in geometry in the 1st floor? (would be like sorting manually the scene collections) Would it be possible to sort all elements depending on their elevation? Cut the elements that range over several floors?

    Where is the IFCPatch menu gone in Blender3.2.1 BlenderBIM 220711 ?

    Thanks.

  19. B

    the call has slightly changed a bit ... see in Source or this example from above here:

    import sys
    
    sys.path.append("/home/hugo/Documents/dev/ifcopenshell/ifcopenshell-official/ifcos/src/ifcpatch/")
    
    import ifcpatch
    
    import ifcopenshell
    
    in_ifcfile = ifcopenshell.open("/home/hugo/NeuOrd/IFC Schependomlaan.ifc")
    
    
    
    
    
    out_ifcfile = ifcpatch.execute({
    
        "input": "/home/hugo/NeuOrd/IFC Schependomlaan.ifc",
    
        "file": in_ifcfile,
    
        "recipe": "ExtractElements",
    
        "arguments": [".IfcWall"],
    
    })
    
    ifcpatch.write(out_ifcfile, "/home/hugo/NeuOrd/IFC Schependomlaan_AllWalls.ifc")
  20. B

    What else can be used as selector? I know of

    ".IfcSomeWhat"
    
    "#AGUID"

    They can be combined by a "|"

    They can even be mixed like get all IfcSlab and than this GUID.

    Can I get the inverse, means all but not IfcSlab?

    Can I get all with material xyz, or pset.attribut with value xyz?

    Where in source is this implementet? It seams not here in ExtractElements.py ... https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcpatch/ifcpatch/recipes/ExtractElements.py or more direct where is the Selector implemented https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcpatch/ifcpatch/recipes/ExtractElements.py#L62

        selector = ifcopenshell.util.selector.Selector()
    
        for element in selector.parse(self.file, self.query):
    
            self.add_element(element)
  21. B

    on huge files it can take some time and on complicated queries it needs some trys to find the correct querry.

    How about the following ...

    I have some own ExtractElements Python code which is from the old times and much less smart than ifcpatch but one thing is quite cool.

    Before it really creates a new ifcfile it does a BIMCollabSmartView and the result can easily be controlled. For ifcpatch we would have to use something more generic like bcf. means instead creating a new ifc it creates a bcf. With this bcf the result can be controlled in just a few seconds. On a new run the ifc does not even be loaded, just load the bcf controll run again as long as it fits, than create the ifc. This is how I do it with my ooold extractor and BIMCollabSmartView.

  22. P

    I am trying to use ifcpatch to create a mini-app in streamlit that extracts an object from an IFC using GUID:

            extracted_ifc = ifcpatch.execute({"input": ifc, "file": ifc, "recipe": "ExtractElements", "arguments": [ f"#{guid}"]})

    From what I see at the moment I can only pass an IfcEntity as an argument, is there any chance to pass a GUID instead? Or am I just passing GUID incorrectly?

  23. P

    @PeterPetersen said:

    I am trying to use ifcpatch to create a mini-app in streamlit that extracts an object from an IFC using GUID:

            extracted_ifc = ifcpatch.execute({"input": ifc, "file": ifc, "recipe": "ExtractElements", "arguments": [ f"#{guid}"]})

    From what I see at the moment I can only pass an IfcEntity as an argument, is there any chance to pass a GUID instead? Or am I just passing GUID incorrectly?

    All sorted, human error - it is f"{guid}" rather than f"#{guid}". Thanks for ifcpatch - it is simply brilliant!

    One more question - is ifcpatch going to be integrated in the ifcopenshell pip distribution? This would make it a lot easier for deployment on the web..

  24. M

    is ifcpatch going to be integrated in the ifcopenshell pip distribution?

    There are plans to. Would you like to help?

  25. P

    There are plans to. Would you like to help?

    Hi Moult, great to hear this will eventually be integrated! As for help - the will is there, but capacity isn't - at least not at the moment (work+PhD+family). I can imagine contributing once my PhD is finished - but this is at least a year away.

  1. Page 1
  2. 2

Login or Register to reply.