Difference between revisions of "BlenderBIM Add-on/Bonsai QuantityTakeoff"
Line 62: | Line 62: | ||
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 | 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 | 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 | + | /bonsai/bim/qto/calculator.py |
and define them. | and define them. | ||
Line 88: | Line 90: | ||
We can look at the other functions and copy past the new functions, maybe at the and of the file. The new functions should look like these: | We can look at the other functions and copy past the new functions, maybe at the and of the file. The new functions should look like these: | ||
− | def get_rebar_beam_weight(o: bpy.types.Object) -> float: | + | 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: | + | 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. | 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. | ||
Line 100: | Line 102: | ||
These lines should be added right under # IfcMassMeasure section under Blender class | These lines should be added right under # IfcMassMeasure section under Blender class | ||
− | # Rebar | + | # Rebar |
− | "get_rebar_beam_weight": Function("IfcMassMeasure", "Beam Rebar Weight", ""), | + | "get_rebar_beam_weight": Function("IfcMassMeasure", "Beam Rebar Weight", ""), |
− | "get_rebar_slab_weight": Function("IfcMassMeasure", "Slab Rebar Weight", ""), | + | "get_rebar_slab_weight": Function("IfcMassMeasure", "Slab Rebar Weight", ""), |
Et voila, now it should be possible to perform the Quantity Take-off custom method with the defined custom ruleset. | Et voila, now it should be possible to perform the Quantity Take-off custom method with the defined custom ruleset. |
Revision as of 16:47, 2 January 2025
Quantity Take-off (QTO)
With Bonsai is possible to perform the Quantity take-off with the operator located under the "Costing and Schedulng" tab (for the december 2024 version). By clicking on "Perform Quantity Take-off" button 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 enought for the majority of usecase but sometimes an user could 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 that contains 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 this actually modifies the files that allows to Bonsai to work so create a backup is always a good advice.
There are the three files that are interesting
- ifc5d folder .json file
In this folder there are the .json files that maps all the classes and properties with the calculating functions. So for example let's open IFC4QtoBaseQuantitiesBlender.json.
The first four lines contains 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, this means that there is no mapping and the calculation are 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 files 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 names located in the folder.
This file also contain the correct definition of the calculating function so, if we add new calculating functions, it is necessary to add also new lines here.
How to create a new ruleset
So let's play a little creating a new ruleset. This could be useful for example in order to perform the rebar weight calculation automatically, multiplying the gross volume with 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 run now Blender, you will already see the new ruleset under the costing and scheduling tab, but of course right now it does the same things of 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 past the new functions, maybe at the and of the file. The new functions should look like these:
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 voila, now it should be possible to perform the Quantity Take-off custom method with the defined custom ruleset.