Remove elements from IFC in Python

Hi! I am currently writing my master thesis and need some help with handling IFC files. I wish to manipulate a m IFC file so that it removes all the elements that are not load bearing (say foreksample every element besides IfcBeam and IfcColum). Then I need to read this IFC file in Grasshopper by using the plugin GeometryGym.

I have managed to write a code that removes everything except IfcBeam and IfcColumn in Python, but when I tried reading it in Grasshopper there are no values in the file. However, the new file works in Solibri.

Here is my Python code:

_import ifcopenshell

f ="My_file.ifc")
beams = f.by_type("IfcBeam")

for instance in f:
if not instance.is_a("IfcBeam") and not instance.is_a("IfcColumn"):

Does anyone have any experience with this and know what the problem may be?
Thank you so much in advance :D


  • Any chance you are able to share your .ifc file?

  • Loads perfect in BIMVision and BlenderBIM too

    but when I tried reading it in Grasshopper are no values in the file.

    Unfortunelaty I have no Rhino with Grasshopper, maybe you could try to ask here?

  • edited March 18

    @Elisemunch you should be using the root.remove_product api function:

    Removing an element is not as simple as you might think - there are many relationships that needs to be considered. For example, are associated properties, materials, profiles, etc also correctly removed?

  • I guess also ping @geometrygym .

    Another approach FYI is to use the ExtractElements IfcPatch which effectively does the opposite, it "copies the element you choose to a new IFC model" instead of deleting the ones you don't want.

  • edited March 19

    Hi Elise,
    Are you sure that the file you posted is the one with elements removed? I see no reference of IfcOpenShell in the file to identify that this might have been post processed. I had a user share a file directly with me last week, and the file was missing IfcProject. This object is mandatory and our tools will not look for orphaned objects. It would explain the behaviour you report. If you are using a similar process, check open the file in a text editor and check the IfcProject is retained.
    I agree with Dion, I have implemented removal of elements in my developments, but I'd advise to filter the objects to retain and duplicate them into the target file. Geometry Gym plugins can facilitate this as an alternative to IfcOpenShell.
    Note that solibri visualizes all products in the file, ignoring whether it is orphaned or not from the spatial structure. I personally would prefer if Solibri did behave this way.



  • Thank you so much to everyone who answered! I am looking into your comments now and it is very clear that i missed some important things in my first code. I will keep you updated :D

  • @Moult I am looking into extracting the elements by using IfcPatch like you recommended, but keep getting the error "No module named "ifcpatch"". Have tried "import ifcpatch", to pip install, and googling of course, but cant get it to work. Do you know how I can fix this?

  • edited March 24

    same here ... I do use this very very often ... I do not remove elements but use ifcpatch to create a new ifc.
    see how to call ifcpatch
    you need to adapt the directories to your ones ...

  • Thank you @bernd !

Sign In or Register to comment.