mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Add info message if some elements were skipped from quantification #5905
Example - https://i.imgur.com/DwklNFS.png
This commit is contained in:
@@ -166,6 +166,7 @@ class PerformQuantityTakeOff(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
props = context.scene.BIMQtoProperties
|
props = context.scene.BIMQtoProperties
|
||||||
|
|
||||||
|
elements: set[ifcopenshell.entity_instance]
|
||||||
if context.selected_objects:
|
if context.selected_objects:
|
||||||
elements = set()
|
elements = set()
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
@@ -179,7 +180,17 @@ class PerformQuantityTakeOff(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
ifc_file = tool.Ifc.get()
|
ifc_file = tool.Ifc.get()
|
||||||
results = ifc5d.qto.quantify(ifc_file, elements, rules)
|
results = ifc5d.qto.quantify(ifc_file, elements, rules)
|
||||||
|
not_quantified_elements = elements - set(results.keys())
|
||||||
ifc5d.qto.edit_qtos(ifc_file, results)
|
ifc5d.qto.edit_qtos(ifc_file, results)
|
||||||
|
|
||||||
self.report({"INFO"}, f"Quantities are calculated for {len(elements)} elements.")
|
not_quantified_message = ""
|
||||||
|
if not_quantified_elements:
|
||||||
|
print("Elements that were not quantified:")
|
||||||
|
for element in not_quantified_elements:
|
||||||
|
print(f"- {element}")
|
||||||
|
not_quantified_message = (
|
||||||
|
f" {len(not_quantified_elements)} of them were not quantified, see system console for the details."
|
||||||
|
)
|
||||||
|
|
||||||
|
self.report({"INFO"}, f"Quantities are calculated for {len(elements)} elements.{not_quantified_message}")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
+12
-12
@@ -28,12 +28,13 @@ import ifcopenshell.util.shape
|
|||||||
import ifcopenshell.util.representation
|
import ifcopenshell.util.representation
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import Any, Literal, get_args
|
from typing import Any, Literal, get_args, Union
|
||||||
|
|
||||||
|
|
||||||
Function = namedtuple("Function", ["measure", "name", "description"])
|
Function = namedtuple("Function", ["measure", "name", "description"])
|
||||||
RULE_SET = Literal["IFC4QtoBaseQuantities", "IFC4QtoBaseQuantitiesBlender"]
|
RULE_SET = Literal["IFC4QtoBaseQuantities", "IFC4QtoBaseQuantitiesBlender"]
|
||||||
rules: dict[RULE_SET, dict[str, Any]] = {}
|
rules: dict[RULE_SET, dict[str, Any]] = {}
|
||||||
|
ResultsDict = dict[ifcopenshell.entity_instance, dict[str, dict[str, float]]]
|
||||||
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
for name in get_args(RULE_SET):
|
for name in get_args(RULE_SET):
|
||||||
@@ -41,13 +42,13 @@ for name in get_args(RULE_SET):
|
|||||||
rules[name] = json.load(f)
|
rules[name] = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
def quantify(ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_instance], rules: dict) -> dict:
|
def quantify(ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_instance], rules: dict) -> ResultsDict:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param rules: Set of rules from `ifc5d.qto.rules`.
|
:param rules: Set of rules from `ifc5d.qto.rules`.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
results = {}
|
results: ResultsDict = {}
|
||||||
for calculator, queries in rules["calculators"].items():
|
for calculator, queries in rules["calculators"].items():
|
||||||
calculator = calculators[calculator]
|
calculator = calculators[calculator]
|
||||||
for query, qtos in queries.items():
|
for query, qtos in queries.items():
|
||||||
@@ -57,12 +58,8 @@ def quantify(ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_inst
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def edit_qtos(ifc_file: ifcopenshell.file, results: dict[ifcopenshell.entity_instance, Any]) -> None:
|
def edit_qtos(ifc_file: ifcopenshell.file, results: ResultsDict) -> None:
|
||||||
"""
|
"""Apply quantification results as quantity sets."""
|
||||||
|
|
||||||
:param results: Results from `ifc5d.qto.quantify`.
|
|
||||||
|
|
||||||
"""
|
|
||||||
for element, qtos in results.items():
|
for element, qtos in results.items():
|
||||||
for name, quantities in qtos.items():
|
for name, quantities in qtos.items():
|
||||||
qto = ifcopenshell.util.element.get_pset(element, name, should_inherit=False)
|
qto = ifcopenshell.util.element.get_pset(element, name, should_inherit=False)
|
||||||
@@ -158,8 +155,8 @@ class IfcOpenShell:
|
|||||||
cls,
|
cls,
|
||||||
ifc_file: ifcopenshell.file,
|
ifc_file: ifcopenshell.file,
|
||||||
elements: set[ifcopenshell.entity_instance],
|
elements: set[ifcopenshell.entity_instance],
|
||||||
qtos: dict,
|
qtos: dict[str, dict[str, Union[str, None]]],
|
||||||
results: dict,
|
results: ResultsDict,
|
||||||
) -> None:
|
) -> None:
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
@@ -298,7 +295,10 @@ class Blender:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate(
|
def calculate(
|
||||||
ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_instance], qtos: dict, results: dict
|
ifc_file: ifcopenshell.file,
|
||||||
|
elements: set[ifcopenshell.entity_instance],
|
||||||
|
qtos: dict[str, dict[str, Union[str, None]]],
|
||||||
|
results: ResultsDict,
|
||||||
) -> None:
|
) -> None:
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import bonsai.bim.module.qto.calculator as calculator
|
import bonsai.bim.module.qto.calculator as calculator
|
||||||
|
|||||||
Reference in New Issue
Block a user