quantitifaction - not to add empty qto if nothing was quantified

It already works that way for ifcopenshell quantitification, making it work the same for Blender quantifications.

Noticed in #6220
This commit is contained in:
Andrej730
2025-02-25 16:39:35 +05:00
parent 2f6ae1745f
commit f63d6b80c5
+9 -6
View File
@@ -380,24 +380,27 @@ class Blender:
import bonsai.bim.module.qto.calculator as calculator
unit_converter = SI2ProjectUnitConverter(ifc_file)
formula_functions = {}
formula_functions: dict[str, types.FunctionType] = {}
for element in elements:
obj = tool.Ifc.get_object(element)
if not obj or obj.type != "MESH":
continue
results.setdefault(element, {})
element_results = {}
for name, quantities in qtos.items():
results[element].setdefault(name, {})
qto_results = {}
for quantity, formula in quantities.items():
if not formula:
continue
if not (formula_function := formula_functions.get(formula)):
formula_function = formula_functions[formula] = getattr(calculator, formula)
if (value := formula_function(obj)) is not None:
results[element][name][quantity] = unit_converter.convert(
value, Blender.functions[formula].measure
)
qto_results[quantity] = unit_converter.convert(value, Blender.functions[formula].measure)
if qto_results:
element_results[name] = qto_results
# Avoid adding empty qsets if nothing was calculated.
if element_results:
results[element] = element_results
calculators = {"Blender": Blender, "IfcOpenShell": IfcOpenShell}