From a883e9f49051ec9756d1f2e178df60c7482753aa Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 25 Jul 2024 17:49:19 +0500 Subject: [PATCH] bsdd - fix bug adding wrong classification to the project + info messages 1) we were identifying active domain just by name, therefore it would always pick up the first dictionary that has matching name (typically it's the most recent version) even though user selected a different version 2) Previously it would fail if it couldn't find a domain, now it will show an info message. 3) Also added info message when user is trying to add the same classification again, so it will be less confusing. --- .../bim/module/classification/operator.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/classification/operator.py b/src/blenderbim/blenderbim/bim/module/classification/operator.py index 99561ec40e..be5ce41c71 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/operator.py +++ b/src/blenderbim/blenderbim/bim/module/classification/operator.py @@ -118,10 +118,22 @@ class AddClassificationFromBSDD(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMBSDDProperties - domain = [d for d in props.domains if d.name == props.active_domain][0] + domain = next((d for d in props.domains if d.name == props.active_domain and d.uri == props.active_uri), None) + + # Maybe user loaded preview domains, set it as active + # and then reloaded them without preview domains. + if not domain: + self.report( + {"INFO"}, + f"Couldn't find domain '{props.active_domain}' ({props.active_uri}). Try to reload bSDD dictionaries.", + ) + return + for element in tool.Ifc.get().by_type("IfcClassification"): if element.Name == props.active_domain or (tool.Classification.get_location(element) == domain.uri): + self.report({"INFO"}, f"Classification '{props.active_domain}' is already added to the project.") return + classification = ifcopenshell.api.run( "classification.add_classification", tool.Ifc.get(), classification=props.active_domain )