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 import bonsai.bim.module.qto.calculator as calculator
unit_converter = SI2ProjectUnitConverter(ifc_file) unit_converter = SI2ProjectUnitConverter(ifc_file)
formula_functions = {} formula_functions: dict[str, types.FunctionType] = {}
for element in elements: for element in elements:
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)
if not obj or obj.type != "MESH": if not obj or obj.type != "MESH":
continue continue
results.setdefault(element, {}) element_results = {}
for name, quantities in qtos.items(): for name, quantities in qtos.items():
results[element].setdefault(name, {}) qto_results = {}
for quantity, formula in quantities.items(): for quantity, formula in quantities.items():
if not formula: if not formula:
continue continue
if not (formula_function := formula_functions.get(formula)): if not (formula_function := formula_functions.get(formula)):
formula_function = formula_functions[formula] = getattr(calculator, formula) formula_function = formula_functions[formula] = getattr(calculator, formula)
if (value := formula_function(obj)) is not None: if (value := formula_function(obj)) is not None:
results[element][name][quantity] = unit_converter.convert( qto_results[quantity] = unit_converter.convert(value, Blender.functions[formula].measure)
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} calculators = {"Blender": Blender, "IfcOpenShell": IfcOpenShell}