From b416df538a648a99c049e6f148d4fc362520047b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 8 Nov 2024 11:13:38 -0300 Subject: [PATCH] Add `AuthoringData.data["relating_type_id_current"]` to model data. --- src/bonsai/bonsai/bim/module/model/data.py | 13 +++++++++---- src/bonsai/bonsai/bim/module/model/workspace.py | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/data.py b/src/bonsai/bonsai/bim/module/model/data.py index b1ec23d038..30ad2bf486 100644 --- a/src/bonsai/bonsai/bim/module/model/data.py +++ b/src/bonsai/bonsai/bim/module/model/data.py @@ -58,6 +58,7 @@ class AuthoringData: cls.data["ifc_classes"] = cls.ifc_classes() cls.data["ifc_class_current"] = cls.ifc_class_current() cls.data["relating_type_id"] = cls.relating_type_id() # only after .ifc_classes() + cls.data["relating_type_id_current"] = cls.relating_type_id_current() # only after .ifc_classes() cls.data["relating_type_name"] = cls.relating_type_name() # only after .relating_type_id() cls.data["relating_type_description"] = cls.relating_type_description() # only after .relating_type_id() cls.data["predefined_type"] = cls.predefined_type() # only after .relating_type_id() @@ -247,18 +248,22 @@ class AuthoringData: return [(str(e.id()), e.Name or "Unnamed", e.Description or "") for e in results] return [] - @classmethod - def relating_type_name(cls): + @classmethod + def relating_type_id_current(cls): relating_type_id = tool.Blender.get_enum_safe(cls.props, "relating_type_id") relating_type_id_data = cls.data["relating_type_id"] if not relating_type_id and relating_type_id_data: relating_type_id = relating_type_id_data[0][0] - if relating_type_id: + return relating_type_id + + @classmethod + def relating_type_name(cls): + if relating_type_id := cls.data["relating_type_id_current"]: return tool.Ifc.get().by_id(int(relating_type_id)).Name or "Unnamed" @classmethod def relating_type_description(cls): - if relating_type_id := cls.props.relating_type_id: + if relating_type_id := cls.data["relating_type_id_current"]: return tool.Ifc.get().by_id(int(relating_type_id)).Description or "No description" @classmethod diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index bfa74713e0..983d0d6bab 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -936,18 +936,18 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator): def hotkey_S_A(self): props = bpy.context.scene.BIMModelProperties + relating_type_id = AuthoringData.data["relating_type_id_current"] + props.relating_type_id = relating_type_id if bpy.context.scene.BIMGeometryProperties.mode == "ITEM": bpy.ops.wm.call_menu(name="BIM_MT_add_representation_item") else: for obj in tool.Blender.get_selected_objects(): obj.select_set(False) - if ( - relating_type_id := tool.Blender.get_enum_safe(props, "relating_type_id") - ) and tool.Model.get_usage_type(tool.Ifc.get().by_id(int(relating_type_id))) == "LAYER2": + if relating_type_id and tool.Model.get_usage_type(tool.Ifc.get().by_id(int(relating_type_id))) == "LAYER2": bpy.ops.bim.draw_polyline_wall("INVOKE_DEFAULT") elif ( - relating_type_id := tool.Blender.get_enum_safe(props, "relating_type_id") - ) and tool.Model.get_usage_type(tool.Ifc.get().by_id(int(relating_type_id))) == "LAYER3": + relating_type_id and tool.Model.get_usage_type(tool.Ifc.get().by_id(int(relating_type_id))) == "LAYER3" + ): bpy.ops.bim.draw_polyline_slab("INVOKE_DEFAULT") else: bpy.ops.bim.add_occurrence("INVOKE_DEFAULT")