diff --git a/src/bonsai/bonsai/bim/__init__.py b/src/bonsai/bonsai/bim/__init__.py index 2a86f92f74..adf8b002ca 100644 --- a/src/bonsai/bonsai/bim/__init__.py +++ b/src/bonsai/bonsai/bim/__init__.py @@ -101,6 +101,7 @@ classes = [ operator.BIM_OT_delete_object, operator.BIM_OT_remove_section_plane, operator.BIM_OT_select_entity, + operator.BIM_OT_select_entity_by_guid, operator.BIM_OT_select_object, operator.BIM_OT_show_description, operator.BIM_OT_multiple_file_selector, diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index 12c5ef259b..54adfce723 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -392,6 +392,7 @@ def draw_filter( row = layout.row(align=True) row.label(text=f"{len(data.data['saved_searches'])} Saved Searches") + row.operator("bim.select_entity_by_guid", text="", icon="CON_OBJECTSOLVER") if data.data["saved_searches"]: row.operator("bim.load_search", text="", icon="IMPORT").module = module row.operator("bim.save_search", text="", icon="EXPORT").module = module diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index ffce1e87f3..0d40334750 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -1049,6 +1049,38 @@ class BIM_OT_select_entity(bpy.types.Operator): return {"FINISHED"} +class BIM_OT_select_entity_by_guid(bpy.types.Operator): + bl_idname = "bim.select_entity_by_guid" + bl_label = "Select Entity by Guid" + bl_description = "Select entity by guid currently saved to clipboard" + bl_options = {"REGISTER", "UNDO"} + + @classmethod + def description(cls, context, properties) -> str: + assert context.window_manager + return f"{cls.bl_description}:\n'{context.window_manager.clipboard.strip()}'" + + def execute(self, context): + assert context.window_manager + + ifc_file = tool.Ifc.get() + guid = context.window_manager.clipboard.strip() + try: + element = ifc_file.by_guid(guid) + except RuntimeError: + self.report({"ERROR"}, f"No IFC element found with guid '{guid}'.") + return {"CANCELLED"} + + obj = tool.Ifc.get_object(element) + if not isinstance(obj, bpy.types.Object): + self.report({"ERROR"}, f"The following element is not present in the scene as Blender object: '{element}'.") + return {"CANCELLED"} + + tool.Blender.select_and_activate_single_object(context, obj) + self.report({"INFO"}, f"Found and selected element: '{obj.name}'.") + return {"FINISHED"} + + class BIM_OT_select_object(bpy.types.Operator): bl_idname = "bim.select_object" bl_label = "Select Object"