From f63d6b80c53cda21a1a31b05adbb083769a0e8cd Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 25 Feb 2025 16:39:35 +0500 Subject: [PATCH] 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 --- src/ifc5d/ifc5d/qto.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ifc5d/ifc5d/qto.py b/src/ifc5d/ifc5d/qto.py index e23ae2f442..2863634f07 100644 --- a/src/ifc5d/ifc5d/qto.py +++ b/src/ifc5d/ifc5d/qto.py @@ -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}