Skip to content

Commit f63d6b8

Browse files
committed
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
1 parent 2f6ae17 commit f63d6b8

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/ifc5d/ifc5d/qto.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,27 @@ def calculate(
380380
import bonsai.bim.module.qto.calculator as calculator
381381

382382
unit_converter = SI2ProjectUnitConverter(ifc_file)
383-
formula_functions = {}
383+
formula_functions: dict[str, types.FunctionType] = {}
384384

385385
for element in elements:
386386
obj = tool.Ifc.get_object(element)
387387
if not obj or obj.type != "MESH":
388388
continue
389-
results.setdefault(element, {})
389+
element_results = {}
390390
for name, quantities in qtos.items():
391-
results[element].setdefault(name, {})
391+
qto_results = {}
392392
for quantity, formula in quantities.items():
393393
if not formula:
394394
continue
395395
if not (formula_function := formula_functions.get(formula)):
396396
formula_function = formula_functions[formula] = getattr(calculator, formula)
397397
if (value := formula_function(obj)) is not None:
398-
results[element][name][quantity] = unit_converter.convert(
399-
value, Blender.functions[formula].measure
400-
)
398+
qto_results[quantity] = unit_converter.convert(value, Blender.functions[formula].measure)
399+
if qto_results:
400+
element_results[name] = qto_results
401+
# Avoid adding empty qsets if nothing was calculated.
402+
if element_results:
403+
results[element] = element_results
401404

402405

403406
calculators = {"Blender": Blender, "IfcOpenShell": IfcOpenShell}

0 commit comments

Comments
 (0)