how to keep only the classes we are looking for in the ifc file (python)

data = ifc.by_type('ifcproduct')
dataKeep = ifc.by_type('IfcRoof'),ifc.by_type('IfcWall'), ifc.by_type('IfcPlate'), ifc.by_type('IfcColumn'), ifc.by_type('IfcSlab')

I want to save only the classes selected in the datakeep list
Thank you

Tagged:

Comments

  • edited May 10

    How about put the those IfcType into a list?

    ifctypes = ["IfcRoof", "IfcWall", "IfcPlate","IfcColumn","IfcSlab"]
    dataKeep = []
    for ifctype in ifctypes:
    dataKeep.append(ifc.by_type(ifctype))

  • Thank you for your reply, except that I am trying to write this list in my output ifc file

  • @chunchk maybe dataKeep.extend(...) is preferred :)

    @Takieddine It depends on what you're trying to do. At the lowest level, you can use [output_ifc.add(element) for e in dataKeep) to add elements from one IFC to another.

    However if you want to extract particular elements of a class with all their properties, geometry, etc you're better off using the IfcPatch recipe for that. See the ExtractElements recipe here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcpatch/ifcpatch/recipes/ExtractElements.py

  • i found it thank you,
    for f in ifc:
    if f.id() not in dataKeep:
    ifc.remove(f)

  • @Takieddine that is a light removal, but it would leave a lot of orphaned data. Can I instead recommend [ifcopenshell.api.run("root.remove_product", model, product=e) for e in dataKeep]?

  • @Moult
    Indeed, my code did not give the right result and your code works perfectly except that I want to do the opposite (keep dataKeep and not delete it)

  • @Takieddine yes, to do the opposite, see my original reply which recommended the ExtractElements recipe. See here for instructions on using the IfcPatch scripts: https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.7.0/src/ifcpatch#readme - you can see the code example which extracts walls. You'd modify it for your scenario like this: .IfcRoof|.IfcWall|.IfcPlate|.IfcColumn|.IfcSlab (notice the . at the start of each class name).

    tlang
  • edited May 16

    @Moult Hello, in the same context I would like to do a geometry work by fixing the X.Y.Z of each point of the building envelope to be able afterwards to keep only the external walls and the roofs as well as the platform and to remove all the internal walls, doors, stairs ..etc. see the example
    I would like to know if ifcopenshell offers a solution for this vision. Please

Sign In or Register to comment.