OSArch Community

IfcOpenShell Python - Calculate Quantities

  1. O

    @Andrej730 said:

    1. You can use get_decomposition() to get elements in the IfcBuildingStorey or in other spatial elements. Using api calls usually simpler as it doesn't require to remember the IFC schema attributes exactly and ignore some caveats there might be along the way.

    Yes, I use the api calls too. In this case I am intentionally using the vanilla IFC code as a way to understand more of the concepts of the IFC Schema especially wrt to ‘relationships’.

    1. To debug this kind of error AttributeError: entity instance of type 'IFC4.IfcPropertySet' has no attribute 'Quantities'. you can print element.IsDefinedBy[0].RelatingPropertyDefinition - it won't be IfcElementQuantity as you expected but IfcPropertySet element that doesn't have Quantities attribute. To workaround you can skip all elements that are not IfcElementQuantity.

    But then you'll also need to handle different type of quantities that can appear in qset - e.g. IfcQuantityLength won't have VolumeValue and accessing it will result in the similar error as above. Then you can either skip them too or do some other logic.

    You’re right it wasn’t ‘ IfcElementQuantity’ and just like @Massimo confirmed but it’s okay now.

    1. Alternatively, you can use another api method get_psets() that has argument to get only quantity sets and will return a dictionary with quantities names and their values which might make them easier to process.

    Noted. Btw is it possible to add the ‘Qto_BaseQuantities’ by code without adding it through BBIM UI setting (eg. SHIFT+Q).

    Pardon the delay some internet problems for the past days.

  2. S

    Noted. Btw is it possible to add the ‘Qto_BaseQuantities’ by code without adding it through BBIM UI setting (eg. SHIFT+Q).

    Yes, I was looking for a solution to that too, it would be nice to find out, thanks

  3. M
  4. O

    @Massimo said:

    If i understand it correctly, the question is about adding the Pset "Qto_BaseQuantities" with the code instead of through BBIM UI, right?

    By code I meant the vanilla IFC Schema without ifcOpenShell api. I am trying to explore the raw code to gain more insights.

  5. M
  6. S

    Hi @Coen :

    import ifcopenshell

    import blenderbim.tool as tool

    from blenderbim.bim.ifc import IfcStore

    ifc_file = ifcopenshell.open(IfcStore.path)

    products = ifc_file.by_type('IfcWall')

    for ifc_product in products:

    ifc_material = ifcopenshell.util.element.get_material(ifc_product)
    if ifc_material:               
        if ifc_material.is_a('IfcMaterialLayerSetUsage'):
            for material_layer in ifc_material.ForLayerSet.MaterialLayers:
                print (material_layer.Material.Name, material_layer.LayerThickness)

    we might have already exchanged this topic somewhere else here but can't find it atm

    how to do the same in Collaboration > Spreadsheet Import/Export ? I tried several combinations without success

    I need to create a .csv with all IfcMaterialLayerSet and relevant material & thickness, like the output in the image but in a .csv file

    thanks

  7. T

    maybe...

    
    {
    
      "query": "IfcWall",
    
      "attributes": [
    
        {
    
          "name": "type.Name",
    
          "header": "TYPE",
    
          "sort": "NONE",
    
          "group": "GROUP",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.0.Material.Name",
    
          "header": "Name - 1st Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.0.LayerThickness",
    
          "header": "Thickness - 1st Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.1.Material.Name",
    
          "header": "Name - 2nd Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.1.LayerThickness",
    
          "header": "Thickness - 2nd Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.2.Material.Name",
    
          "header": "Name - 3rd Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        },
    
        {
    
          "name": "material.item.2.LayerThickness",
    
          "header": "Thickness - 3rd Layer",
    
          "sort": "NONE",
    
          "group": "NONE",
    
          "summary": "NONE",
    
          "formatting": "{{value}}"
    
        }
    
      ],
    
      "settings": {
    
        "should_generate_svg": false,
    
        "should_preserve_existing": false,
    
        "include_global_id": false,
    
        "null_value": "N/A",
    
        "empty_value": "-",
    
        "true_value": "YES",
    
        "false_value": "NO",
    
        "concat_value": ", ",
    
        "csv_delimiter": ",",
    
        "format": "ods",
    
        "csv_custom_delimiter": ""
    
      }
    
    }
    
    

  8. S

    @theoryshaw said:

    maybe...

    yes, I missed the number between "material.item.X.LayerThickness"

    thank you!

  9. C

    @steverugi

    Glad I could help 😂😂🤓

  10. L

    Hi. I'm wondering if I'm using the Calculate all properties tool wrong or if something is broken on my side. I start by importing the ifc file, then I press a to select all. Next, I'll open the "BlenderBIM" tab and click "Calculate All Quantities". There is no feedback apart from a small blinking in the 3D view. If I inspect an object, there doesn't seem to have been any changes if I look at the "Object Information" tab.

    Next, I use save IFC project as..from the file menu to save the updated file. If I compare the before and after file the only change is the time and stamp. There are no other changes in the ifc file.

    I've tested with only one object selected as well. Each of the Calculate Circle, Edge, Face, and Volume buttons will return a value in "Result". But pressing "Assign IFC Object Quantity Set" or "Calculate All Quantiles" does not seem to do anything. I cannot see that anything happens in The Object Information panel but the Info panel reports: bpy.ops.bim.assign_objects_base_qto() and bpy.ops.bim.calculate_all_quantities()

    What am I doing wrong?

  11. S

    Hi @Lars

    Hi. I'm wondering if I'm using the Calculate all properties tool wrong or if something is broken on my side. I start by importing the ifc file, then I press a to select all. Next, I'll open the "BlenderBIM" tab and click "Calculate All Quantities". There is no feedback apart from a small blinking in the 3D view. If I inspect an object, there doesn't seem to have been any changes if I look at the "Object Information" tab.

    Next, I use save IFC project as..from the file menu to save the updated file. If I compare the before and after file the only change is the time and stamp. There are no other changes in the ifc file.

    I've tested with only one object selected as well. Each of the Calculate Circle, Edge, Face, and Volume buttons will return a value in "Result". But pressing "Assign IFC Object Quantity Set" or "Calculate All Quantiles" does not seem to do anything. I cannot see that anything happens in The Object Information panel but the Info panel reports: bpy.ops.bim.assign_objects_base_qto() and bpy.ops.bim.calculate_all_quantities()

    did you try to

    1. use Grouping and Filtering in Project Overview (at the bottom)

    2. add a Class filter and use IfcBuildingElement

    3. deselect everything before clicking on Search button to make sure you select only the filtered elements

    4. with the selection active, on the N menu on the right, go to BlenderBim > Quantity Take-off > Calculate All Quantities

    5. to see if it worked select any element and check its Object Information > Quantity Sets, they should be visible there

    hope it helps, cheers

  12. L

    @steverugi

    Thanks for the tip of using the filter :-) Apart from that the result is unfortunately the same. No new properties or values were added to the selected objects. I have a feeling that something is broken on my side. I'll download a more recent/stable version of the BlenderBIM plugin and try again. I'm currently using version 0.0.240502 onBlender 4.1 (Ubuntu 22.04)

  13. M

    @Lars can you share the IFC model?

  14. L

    OK. I got a step further. It seems I have to save the imported project to a blend file before the feature starts working. In my first attempt, I only opened the IFC file without saving to a .blend file. Once the .blend file was saved things started working. I managed to create Quantity_sets for a few walls. But not all. Some walls give the following error message:

     File "/.../.config/blender/4.1/scripts/addons/blenderbim/tool/ifc.py", line 211, in execute
    
        IfcStore.execute_ifc_operator(self, context)
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/ifc.py", line 349, in execute_ifc_operator
    
        result = getattr(operator, "_execute")(context)
    
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/module/qto/operator.py", line 198, in _execute
    
        core.calculate_objects_base_quantities(tool.Ifc, tool.Cost, tool.Qto, QtoCalculator(), selected_objects = context.selected_objects)
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/core/qto.py", line 48, in calculate_objects_base_quantities
    
        calculate_object_base_quantities(ifc, cost, qto, calculator, obj)
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/core/qto.py", line 66, in calculate_object_base_quantities
    
        calculated_quantities = qto.get_calculated_object_quantities(calculator, base_quantity_name, obj)
    
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/tool/qto.py", line 101, in get_calculated_object_quantities
    
        return {
    
               ^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/tool/qto.py", line 105, in <dictcomp>
    
        and (value := calculator.calculate_quantity(qto_name, quantity_name, obj)) is not None
    
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/module/pset/qto_calculator.py", line 65, in calculate_quantity
    
        value: float = eval(string)
    
                       ^^^^^^^^^^^^
    
      File "<string>", line 1, in <module>
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/module/pset/qto_calculator.py", line 799, in get_gross_side_area
    
        gross_side_area = self.get_lateral_area(obj, exclude_end_areas=True, subtract_openings=False, main_axis="x") / 2
    
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/module/pset/qto_calculator.py", line 776, in get_lateral_area
    
        0 if subtract_openings else self.get_opening_area(obj, angle_z1=angle_z1, angle_z2=angle_z2)
    
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/bim/module/pset/qto_calculator.py", line 710, in get_opening_area
    
        if ifc_opening_element.PredefinedType is not None
    
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/.../.config/blender/4.1/scripts/addons/blenderbim/libs/site/packages/ifcopenshell/entity_instance.py", line 197, in __getattr__
    
        raise AttributeError(
    
    AttributeError: entity instance of type 'IFC2X3.IfcOpeningElement' has no attribute 'PredefinedType'
  15. M

    @Lars it should work also without the blend file but if it works, good to know :-)

    The real problem is because the model is IFC2x3, so that schema hasn't the right Qto PSet..you should update the model i guess... :-)

  16. L

    @Massimo Thanks, but I don't think that is the reason. The feature does work for many objects like windows, wall standardcase and slabs it works nicely. For other objects, it gives the error above. It seems to fail more often on complex geometry of elements with holes in them, but there is no clear pattern. When I save the project, the result is correctly written as IfcElementQuantity according to ifc2x3:

    So there must be something else going on. The IFC file I've imported gives no errors when validating using ifcOpenshell (I'm unfortunately not able to share the file)

  17. L

    I downloaded the most recent build of blenderBIM (https://github.com/IfcOpenShell/IfcOpenShell/compare/blenderbim-240527...v0.7.0) as there were commit messages related to QTO in the build. One with the title "limit quantity types for each resource based on IFC documentation"

    After a brief test, I found :

    • it's no longer possible to calculate quantiles for the objects that used to work before. Maybe ifc 2x3 no longer is supported? If so why?

    • I no longer get any error messages. Nor any messages saying that ifc2x3 isn't supported.

    • QTO has moved under "Costing and Scheduling" This might make sense from a grouping perspective, but in general I find it cumbersome having to move between tabs just to check if the function did what it was supposed to do. Personally, I would like to see the tools that "do something on selections" in a toolbox that can be visible at the same time as the panel where you see the properties of the selected objects. On the positive side, I can quickly jump between tabs using Ctrl+tab.

  18. L

    Short update. Dion told me the QTO feature was in a bit of a flux at the moment. I'll cross my fingers and wait for the next official update. Ifc 2x3 will (still) be supported.

  19. A

    Where this model origanates from? Was it IFC4 file downgraded to IFC2X3 or ...?

    As Massimo mentioned above e.g. Qto_WallBaseQuantities was added only in IFC4, therefore there are issues with using it on IFC2X3.

  20. L

    @Andrej730 said:

    Where this model origanates from? Was it IFC4 file downgraded to IFC2X3 or ...?

    As Massimo mentioned above e.g. Qto_WallBaseQuantities was added only in IFC4, therefore there are issues with using it on IFC2X3.

    The file mentioned above is an IFC2X3 file with Qto_WallBaseQuantities added from BlenderBIM (using BlenderBIM 0.0.240502). I know IFC2X3 doesn't have built-in Qto support like IFC4. However, it would be great if BlenderBIM could offer a way to improve IFC2X3 quantities by calculating and storing property sets (psets) with IFC4 Qto names and properties, while ensuring compatibility with the IFC2X3 standard as outlined in https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcproductextension/lexical/ifcelementquantity.htm.

  21. A

    @Lars said:

    The file mentioned above is an IFC2X3 file with Qto_WallBaseQuantities added from BlenderBIM (using BlenderBIM 0.0.240502).

    But how? Qto_WallBaseQuantities is not available from dropdown list in ifc2x3 as it's not present in ifc2x3 templates.

  22. L

    I can't really explain why it happened, but what I did was to open the ifc2x3 file. Save the .blend file. Then select a few objects (walls, slabs and windows) and then click "Calculate All Quantities". The quantities then appeared on the Object Information panel. Finally, I saved the project back to ifc2x3 an opened in notepad++ to inspect. (the screenshot above) This was on BlenderBIM 0.0.240502 while the tool was still on its own tab to the left of the properties panel. The feature worked for some objects and gave an error message for others. (See above)

  1. Page 1
  2. 2
  3. 3

Login or Register to reply.