From ca0e4f9cd6f38845d458e832490f01b996cf6368 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 23 Oct 2024 17:29:21 +0500 Subject: [PATCH] Fix error duplicating type when current tool doesn't match the type #5591 --- src/bonsai/bonsai/bim/module/type/operator.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/type/operator.py b/src/bonsai/bonsai/bim/module/type/operator.py index 0a6742bdc3..0ce7d85058 100644 --- a/src/bonsai/bonsai/bim/module/type/operator.py +++ b/src/bonsai/bonsai/bim/module/type/operator.py @@ -24,6 +24,7 @@ import ifcopenshell.util.representation import ifcopenshell.util.type import ifcopenshell.util.unit import ifcopenshell.api +import bonsai.bim.helper import bonsai.tool as tool import bonsai.core.geometry import bonsai.core.type as core @@ -315,6 +316,12 @@ class DuplicateType(bpy.types.Operator, tool.Ifc.Operator): tool.Blender.select_and_activate_single_object(context, new_obj) else: self.report({"INFO"}, "Type object can't be selected : It may be hidden or in an excluded collection.") - context.scene.BIMModelProperties.ifc_class = new.is_a() - context.scene.BIMModelProperties.relating_type_id = str(new_obj.BIMObjectProperties.ifc_definition_id) + + props = context.scene.BIMModelProperties + + ifc_class = new.is_a() + # Set duplicated type as active in current tool. + if ifc_class in (i[0] for i in (bonsai.bim.helper.get_enum_items(props, "ifc_class", context) or ()) if i): + context.scene.BIMModelProperties.ifc_class = new.is_a() + context.scene.BIMModelProperties.relating_type_id = str(new_obj.BIMObjectProperties.ifc_definition_id) return {"FINISHED"}