BlenderBIM Add-on/Bonsai QuantityTakeoff
Quantity Take-off (QTO)
With Bonsai it is possible to perform Quantity take-off with the operator located under the "Costing and Scheduling" tab (as of the December 2024 version). By clicking on the "Perform Quantity Take-off" button it is possible to perform the quantity dimension calculation and assign these values to the standard Quantity Set defined by the schema for that specific class.
By default, it is possible to choose between these two "ruleset":
- IFC4 Base Quantities - IfcOpenShell
- IFC4 Base Quantities - Blender
In simple words, the main difference between these two rulesets is that the first one uses the IfcOpenShell geometry processor and the second one uses Blender (TODO: explain this concept better).
These two rulesets are enough for the majority of use case but sometimes a user may want to modify or add new rulesets in order to perform custom calculations.
At the moment it is not possible to simply add a new ruleset without modifying the code, but modify the code is not so difficult to add a new one and this is a perfect example for the Free Software Foundation "red shoes example" (don't you know it? https://u.fsf.org/shoetool)
First of all you need to find where are the folders containing the files that Bosai actually uses. If you are not sure where they are located you can look at the installation scripts located into this folder:
/src/bonsai/scripts/installation/
For example, in Linux, the folder is "$HOME/.config/blender/4.3/extensions/.local/lib/python3.11/site-packages"
Pay attention that, since this actually modifies the files that allows Bonsai to work, it's always a good advice to make a backup.
There are the three files that are interesting:
- ifc5d folder .json file
In this folder there are the .json files that map all the classes and properties with the calculating functions. So for example let's open IFC4QtoBaseQuantitiesBlender.json:
The first four lines contain infos about the ruleset (Name, Description) and the type of the "calculator" (Blender in this case).
The other lines map the object property standard class with the blender calculating function. If there is a Null
instead of the calculating function name, it means that there is no mapping and the calculation is not performed.
For example, "IfcActuator": {Qto_ActuatorBaseQuantities": {"GrossWeight": null}} will not performed but "IfcWall": {"Qto_WallBaseQuantities": {"GrossVolume": "get_gross_volume"}} will be performed.
In this case, this means that, for every IfcWall object, there will be created a new Quantity Set called "Qto_WallBaseQuantities", with the "GrossVolume" property and the function "get_gross_volume" will be used to calculate the (gross) volume.
So, where are these functions? Because this ruleset uses the Blender calculator, the calculating functions are stored here:
- /bonsai/bim/qto/calculator.py
This file contains the calculating functions so, for example, if you open it you will find the "get_gross_volume" function and you can see what the function actually does in order to perform the calculation:
- /ifc5d/qto.py
In this file there is the RULE_SET variable definition that is a list of all the available rulesets. It needs to correspond with the .json file name located in the folder.
This file also contains the correct definition of the calculating function so, if we add new calculating functions, it is necessary to add also new lines there.
How to create a new ruleset
So let's play a little with creating a new ruleset. This could be useful for example in order to perform the rebar weight calculation automatically, multiplying the gross volume times a constant value.
First of all, copy an existing .json file (for simplicity let's copy IFC4QtoBaseQuantitiesBlender.json) and rename it as you want (IFC4QtoBaseQuantitiesBlenderRebar.json), and add the same string into the /ifc5d/qto.py RULE_SET variable so it should be like this:
RULE_SET = Literal["IFC4QtoBaseQuantities", "IFC4QtoBaseQuantitiesBlender", "IFC4QtoBaseQuantitiesBlenderRebar"]
If you now run Blender, you will already see the new ruleset under the "Costing and Scheduling" tab, but of course right now it does the same things as the Blender one.
So let's open the IFC4QtoBaseQuantitiesBlenderRebar.json file and do some customization.
First of all, let's change the name in the second line into something like "My Ruleset - Rebar" and the description "This ruleset quantifies rebar weight starting from the object gross volume". Let's keep the blender calculation and focus on the mapping.
For simplicity, just keep only IfcBeam and IfcSlab objects and delete the others. For the rebar purpose, it is good because beams and slabs have different rebar weight constant. After the modification, the file should look like this:
{ "name": "My Ruleset - Rebar", "description": "This ruleset quantifies rebar weight starting from the object gross volume", "calculators": { "Blender": { "IfcBeam": { "Qto_BeamRebarQuantities": { "RebarWeight": "get_rebar_beam_weight" } }, "IfcSlab": { "Qto_SlabRebarQuantities": { "RebarWeight": "get_rebar_slab_weight" } } } } }
Let's notice that we haven't yet defined the new calculating functions "get_rebar_beam_weight" and "get_rebar_slab_weight", so let's open the file:
/bonsai/bim/qto/calculator.py
and define them.
We can look at the other functions and copy/paste the new functions, maybe at the and of the file. The new functions should look like:
def get_rebar_beam_weight(o: bpy.types.Object) -> float: constant_beam_rebar = 250 return constant_beam_rebar * get_gross_volume(o)
def get_rebar_slab_weight(o: bpy.types.Object) -> float: constant_slab_rebar = 100 return constant_slab_rebar * get_gross_volume(o)
The last step is to define these new functions also in the /ifc5d/qto.py file in order to correctly add the new calculating function.
These lines should be added right under # IfcMassMeasure section under Blender class
# Rebar "get_rebar_beam_weight": Function("IfcMassMeasure", "Beam Rebar Weight", ""), "get_rebar_slab_weight": Function("IfcMassMeasure", "Slab Rebar Weight", ""),
Et voilà, now it should be possible to perform the Quantity Take-off method with a custom defined ruleset.