[IfcOpenShell] Removing IFC data

edited June 25 in General

Hi. Just wondering if it was possible to remove p_sets or other metadata using ifcopenshell and/or blenderBIM

Tagged:

Comments

  • You mean an ifcpatch to remove a list of psets ?
    Else in Blender + BIM addon of course you can remove any attribute/property/pset.

  • Hi everyone. I'm coming back to this item. The link above broke, but I'm assuming the updated one is: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py
    I've been able to get to the python console, but wondering if you could provide an example. My use case would be to remove all p_sets from an ifc, i.e. retain all geometry and type name, but no more.

  • @edwinguerra purging is not the same as "unassign a pset from a product", which is more an authoring usecase that I suggested above. For purging, here's some untested code which should be more efficient.

    import ifcopenshell
    f = ifcopenshell.open('model.ifc')
    for rel in f.by_type('IfcRelDefinesByProperties'):
        ifcopenshell.util.element.remove_deep(f, rel.RelatingPropertyDefinition)
        f.remove(rel)
    

    But may I ask why you are doing this? I have had similar requests in the past, usually because companies are afraid of their "IP" being lost or wanting to cripple BIM data for a recipient that they don't have a good relationship with. If so, I highly recommend you think twice about what you're doing, since the whole point of OSArch is to work together more.

  • Thanks Dion. Yes, it is along the lines of limiting liability when sharing to external parties, like a contractor, when not previously agreed upon or paid for. There are model release forms and all, but still there seems to be interest to prevent any further unintended use. A workflow exists currently which is to export to fbx, but I think IFC would be preferable. I agree, that the best would be to make the whole model and information available, yet there is still the belief that the contractor/subcontractor will get an advantage by using the model in its complete form. And then there are the modeling shortcuts that people take, so things may look good in 2D, but not in the actual model. Would be curious to know your thoughts on this. It would be great if in the future model was released alongside drawings. Preventing the manual take-off of items by all bidding parties alone would improve the karma of the industry.

  • My recommendation, without knowing your full situation, is to simply give them as much data as possible using open digital formats. At this moment, drawings are treated as the legal source of truth so if they misinterpret your model data (e.g. when modeling shortcuts are used), that is on them. Money being spent to recreate withheld data is a wasted opportunity for our built environment, especially when a lot of that money is in the public sector, or could otherwise be used to invest in innovation, sustainability, and other initiatives which, much like "open source / transparency", often get cut first from a project as a low priority item.

    We are already trending towards models being used as legal submissions and I know of a few projects where this is the case. We're already struggling to get rudimentary correct data in our models, let alone with people purposely sabotaging them.

    Coen
  • edited October 2021

    @Moult said:
    @edwinguerra purging is not the same as "unassign a pset from a product", which is more an authoring usecase that I suggested above. For purging, here's some untested code which should be more efficient.

    import ifcopenshell
    f = ifcopenshell.open('model.ifc')
    for rel in f.by_type('IfcRelDefinesByProperties'):
        ifcopenshell.util.element.remove_deep(f, rel.RelatingPropertyDefinition)
        f.remove(rel)
    

    But may I ask why you are doing this? I have had similar requests in the past, usually because companies are afraid of their "IP" being lost or wanting to cripple BIM data for a recipient that they don't have a good relationship with. If so, I highly recommend you think twice about what you're doing, since the whole point of OSArch is to work together more.

    unfortunately the code snipped returns the following error:

    Warning:AttributeError : 'file' object has no attribute 'batch' [' File "", line 119, in \n', ' File "C:\Users\xxxxx\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages\ifcopenshell\util\element.py", line 126, in remove_deep\n ifc_file.batch()\n', ' File "C:\Users\xxxxx\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages\ifcopenshell\file.py", line 95, in getattr\n return getattr(self.wrapped_data, attr)\n', ' File "C:\Users\xxxxx\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 1419, in \n getattr = lambda self, name: _swig_getattr(self, file, name)\n', ' File "C:\Users\xxxxx\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages\ifcopenshell\ifcopenshell_wrapper.py", line 80, in _swig_getattr\n raise AttributeError("\'%s\' object has no attribute \'%s\'" % (class_type.name, name))\n']

    @Moult to your question why to do this:
    quite frequently i am receiving ifc data containing corrupt psets - meaning missing properties, ... or containing unagreed psets. in order to clean those files for further work i try to remove those unwanted data.
    peter

  • @PeterKop you are getting that error because you are using an outdated version of IfcOpenShell. You can download the latest from here: https://github.com/IfcOpenBot/IfcOpenShell/commit/61e510e45c00f303086a618a6dfd81e1d016d0c3

  • @Moult it was not an outdated version but a syntax error in my code. unfortunately;-)

    Moult
  • edited June 21

    Is there really not a counterpart to

    ifcopenshell.api.run("pset.edit_pset", ifcfile, pset=the_pset, properties=the_property)

    for removing a property from a pset and from a ifcfile?

    I would like to delete some properties depending on the property value.

  • How to get rid of an entire IFC file in BlenderBIM using python?
    I used this, but it does not work

    bpy.ops.bim.unload_project(filepath=file_ifc)
    

    Console says it does not recognise the filepath, while it recognises filepath when using load_project :

    bpy.ops.bim.load_project(filepath=file_ifc)
    
  • There is an IfcStore.purge() method that wipes the current IFC model in memory.

    In the Homemaker-addon to refresh the scene, I just delete all the blender collections, then I call import_ifc.IfcImporter().execute() without giving it a filename and it will regenerate the blender model from whatever is in IfcStore.

    This is all a bit if a hack, there ought to be some nice utility methods in blenderbim that do the same things.

  • @brunopostle
    I did not know about IfcStore.purge().
    I now did it like this:

    project = ifc_file.by_type('IfcProject')
    
    for i in project:
        collection_name = 'IfcProject/' + i.Name
    
    collection = bpy.data.collections.get(str(collection_name))
    
    for obj in collection.objects:
        bpy.data.objects.remove(obj, do_unlink=True)
    
    bpy.data.collections.remove(collection)
    bpy.ops.bim.load_project(filepath=file_ifc)
    

    Are there maybe any things I'm not aware off? This seems to work

  • I have a problem where the undo history gets slightly messed-up doing this sort of thing (see pull request #2200), but otherwise it works

  • I got NameError: name 'ifc_file' is not defined, guess I missed to import something.

  • @Max ifc_file is probably a reference to an IfcOpenShell model. You can retrieve the model from blenderbim like so:

    from blenderbim.bim.ifc import IfcStore
    ifc_file = IfcStore.file
    
    Max
  • @Max said:
    I got NameError: name 'ifc_file' is not defined, guess I missed to import something.

    @Max
    Or like this

    import ifcopenshell
    ifc_file = ifcopenshell.open("[c:\path\to\your\ifcfile"])
    
    Max
  • I made my above post into little function which you could place at the end of your python script so it loads the changed model in BlenderBIM, it now also works when no IFC is loaded yet in BlenderBIM.

    def load_ifc_automatically():
    
        if (bool(ifc_file)) == True:
    
            project = ifc_file.by_type('IfcProject')
    
            if project is not None:
    
                for i in project:
                    collection_name = 'IfcProject/' + i.Name
    
                collection = bpy.data.collections.get(str(collection_name))
    
                if collection is not None:
                    for obj in collection.objects:
                        bpy.data.objects.remove(obj, do_unlink=True)
    
                    bpy.data.collections.remove(collection)
    
            bpy.ops.bim.load_project(filepath=file_ifc)
    
    load_ifc_automatically()
    

    No idea if this is good practice or not, but it seems to work.

    theoryshaw
  • A call to bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True) right before the last line of the function will also purge the data from the blend file.

    brunopostleCoenvpajic
Sign In or Register to comment.