IFC to Energy simulation

I am convinced that the combination Blender/BlenderBim/Topologic is the best thing sinnce sliced bread but it is a daunting task to learn to use these tools. My main goal is to convert IFC-files intended for collision control to a models that can be used for energy simulations, prefarebly IDA ICE. The process will probably depend a lot of the avalable information in the IFC, most importantly if there are spaces and the quality of these. My first task/question is pretty easy, what would be the easiest way to isolate and only show the spaces in an IFC in Blender and export them into a .obj-file?

Comments

  • Hi @Max the first thing to do would be to see if the IFC file actually contains any IFCSPACE entities. In blender use the Select -> Select Pattern menu item, and search for ifcspace*. If this works then you can isolate them with Select -> Invert, followed by Object -> Show/Hide -> Hide Selected

  • Thanks a lot, that was surprisingly easy. Now to my next question. Sice ifcspaces are very important for energy simulations I would like to visualize them clearly. Therefore I would like to make all non ifcspaces rather transparent and the ifcspaces slightly transparent with a separate color and wonder how to do this?

  • Hi @Max, I'm ashamed to say that I know how to do this programmatically, but don't know how to do it in the blenderbim UI. Maybe someone can help?

    The simplest way to do it is to select the objects, and assign them blender materials with different transparency/opacity.

  • edited February 2022

    @brunopostle

    I know how to do this programmatically,

    Could you please share this python code? Highly interested in how to make IFC elements transparent with code.

  • Thanks, that was surprisingly tricky. I managed to change color/alpha of a few spaces but not all of them. Could you please help me a little more how to assign materials as simple as possible?

  • edited February 2022

    @Coen said:
    Could you please share this python code? Highly interested in how to make IFC elements transparent with code.

    There is more than one way to style an IFC Product (a Wall, Space etc..), @moult recently added a whole bunch of shader stuff that I haven't even looked at yet, so the below is how I have been doing it so far.

    Typically you would create a Surface Style, assign it to a Material, and then assign the Material to the Product or Type Product you want to style, but in this case assigning a Material to a Space doesn't make much sense, so you may as well do it directly. The thing to remember is that you don't assign the style to the Product directly; a Product can have zero or more Shape Representations, so you assign it to one of these.

    Ideally you loop through the Representations and style only those that have a RepresentationIdentifier of Body, but assuming there is only one Shape Representation for your Space, you can grab it like this:

    my_shape_representation = my_space.Representation.Representations[0]
    

    Create a Surface Style, file is your IfcOpenShell model:

        my_style = ifcopenshell.api.run("style.add_style", file, name="My Style")
    

    ..and give it a Surface Style Rendering (note that blenderbim can now do Surface Style Shading, which is much more sophisticated and has lots more bells and whistles):

       ifcopenshell.api.run(
            "style.add_surface_style",
            file,
            style=my_style,
            attributes={
                "SurfaceColour": {
                    "Name": "Orange",
                    "Red": 1.0,
                    "Green": 0.5,
                    "Blue": 0.0,
                },
                "Transparency": 0.5,
                "ReflectanceMethod": "MATT",
            },
        )
    

    (Note Transparency = 0.5 means that the shape is half transparent, 0.0 would be opaque, 1.0 would be invisible) All you have to do now is assign this Surface Style to your Shape Representation. If you are assigning this Surface Style to a Material, you use style.assign_material_style instead:

        ifcopenshell.api.run(
            "style.assign_representation_styles",
            file,
            shape_representation=my_shape_representation,
            styles=[my_style],
        )
    

    If you are doing this in blenderbim, this won't update in the viewport, I'm not really sure how to do this correctly. In the Homemaker add-on I just delete the Blender collection (along with all the blender 3D versions of your IFC elements) overwrite blenderbim.bim.ifc.IfcStore.file with my file and trigger ifc_importer.execute(), it seems to work.

    Coen
  • I think I am doing something wrong, I want to loop over all the spaces in the IFC model, but not much is happing. I also don't get an error in the console

        import blenderbim.bim.import_ifc
        from blenderbim.bim.ifc import IfcStore
        import blenderbim.tool as tool
        import ifcopenshell
    
    ifc_file = ifcopenshell.open(IfcStore.path)
    products = ifc_file.by_type('IfcProduct')
    my_style = ifcopenshell.api.run('style.add_style', ifc_file, name='My Style') 
    
    ifcopenshell.api.run(
        'style.add_surface_style',
        ifc_file,
        style=my_style,
        attributes={
            'SurfaceColour': {
                'Name': 'Orange',
                'Red': 1.0,
                'Green': 0.5,
                'Blue': 0.0,
            },
            'Transparency': 0.5,
            'ReflectanceMethod': 'MATT',
        },
    )
    for product in products:
        if product.is_a() == 'IfcSpace':
            my_shape_representation = (product.Representation.Representations[0])
            ifcopenshell.api.run(
                'style.assign_representation_styles',
                ifc_file,
                shape_representation=product.Representation.Representations[0],
                styles=[my_style],
            )
    

    ```

  • @Coen No errors is good! What happens if you write the IFC file to disk and import it into a new session? As I say, I don't know how to make a change to the IFC data and dynamically update the blender objects in the viewport.

  • @Coen Also it looks like you are creating a new file object with the path derived from the current blenderbim project:

    ifc_file = ifcopenshell.open(IfcStore.path)
    

    You may have to reassign the blenderbim model at the end:

    IfcStore.file = ifc_file
    

    For debugging, try saving to disk and see what this looks like:

    ifc_file.write("mytestproject.ifc")
    
  • @Coen or just operate on IfcStore.file in the first place

  • @brunopostle

    I think the main problem is that I am an idiot. I tried a different approach.
    The IfcSpace doest not have a material assigned.
    I went to make a new material in BlenderBIM and assign it to an IfcSpace

    Then I selected an IfcSpace
    and found this on the internet

    import bpy
    
    # Get the object in context
    obj = bpy.context.object
    
    # Get the active material
    mat = obj.active_material
    
    # Set the alpha value of the diffuse color
    mat.diffuse_color = (0.0 , 0.0 , 1.0 , 0.7)
    
    

    The result

  • @Coen does this change the IFC data? i.e. does it survive saving and importing the IFC file?

  • @brunopostle said:
    @Coen does this change the IFC data? i.e. does it survive saving and importing the IFC file?

    Tried to export to see what happens, got the following error

    location: <unknown location>:-1
    Error: Python: Traceback (most recent call last):
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\module\project\operator.py", line 761, in invoke
        return self.execute(context)
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\module\project\operator.py", line 769, in execute
        return IfcStore.execute_ifc_operator(self, context)
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\ifc.py", line 299, in execute_ifc_operator
        result = getattr(operator, "_execute")(context)
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\module\project\operator.py", line 796, in _execute
        ifc_exporter.export()
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\export_ifc.py", line 45, in export
        IfcStore.update_cache()
      File "C:\Users\cclaus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\blenderbim\bim\ifc.py", line 99, in update_cache
        ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
    TypeError: unsupported operand type(s) for +: 'file' and 'str'
    
    location: <unknown location>:-1
    
    

    Went to import the IFC again, did the same thing. This time with a succesful export.
    Tried opening it other IFC viewers, seeing if the properties of that specific IfcSpace changed.

    Don't think anything changed

    By the way, there is some weird stuff going on with this sample model. IfcMember contained inside an IfcSpace?

    It also doesnot show the spaces correcly in any IFC viewer like I'm used to.

  • @Coen it would be normal to have some Building Element like a Window, Door, or Slab contained in a Space. A Member seems a bit weird, but I suspect that all things can be found in IFC files in the wild.

    Coen
Sign In or Register to comment.