From ff4d3adf0bfd678307d3d8f1fb2abf06d503d8f6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 27 Jan 2025 17:36:48 +0500 Subject: [PATCH] Select Layer In Layers UI Example - https://imgur.com/a/bXctIxc --- .../bonsai/bim/module/geometry/operator.py | 1 + src/bonsai/bonsai/bim/module/geometry/prop.py | 2 ++ src/bonsai/bonsai/bim/module/geometry/ui.py | 3 +++ .../bonsai/bim/module/layer/__init__.py | 1 + .../bonsai/bim/module/layer/operator.py | 19 +++++++++++++++++++ 5 files changed, 26 insertions(+) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 31511562e7..ddd66baa1d 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2364,6 +2364,7 @@ class EnableEditingRepresentationItems(bpy.types.Operator, tool.Ifc.Operator): new.surface_style_id = style.id() elif inverse.is_a("IfcPresentationLayerAssignment"): new.layer = inverse.Name or "Unnamed" + new.layer_id = inverse.id() elif inverse.is_a("IfcShapeRepresentation"): if inverse.OfShapeAspect: shape_aspect = inverse.OfShapeAspect[0] diff --git a/src/bonsai/bonsai/bim/module/geometry/prop.py b/src/bonsai/bonsai/bim/module/geometry/prop.py index 50e2b19d04..5407c24739 100644 --- a/src/bonsai/bonsai/bim/module/geometry/prop.py +++ b/src/bonsai/bonsai/bim/module/geometry/prop.py @@ -131,6 +131,7 @@ class RepresentationItem(PropertyGroup): surface_style: StringProperty(name="Surface Style") surface_style_id: IntProperty(name="Surface Style ID") layer: StringProperty(name="Layer") + layer_id: IntProperty(name="Layer ID") ifc_definition_id: IntProperty(name="IFC Definition ID") shape_aspect: StringProperty(name="Shape Aspect") shape_aspect_id: IntProperty(name="Shape Aspect IFC ID") @@ -141,6 +142,7 @@ class RepresentationItem(PropertyGroup): surface_style: str surface_style_id: int layer: str + layer_id: int ifc_definition_id: int shape_aspect: str shape_aspect_id: int diff --git a/src/bonsai/bonsai/bim/module/geometry/ui.py b/src/bonsai/bonsai/bim/module/geometry/ui.py index c7f8133a79..7bf70afb9a 100644 --- a/src/bonsai/bonsai/bim/module/geometry/ui.py +++ b/src/bonsai/bonsai/bim/module/geometry/ui.py @@ -236,6 +236,9 @@ class BIM_PT_representation_items(Panel): row.prop(props, "is_editing_item_layer", icon="CANCEL", text="") else: row.label(text=layer or "No Presentation Layer", icon="STICKY_UVS_LOC") + if layer: + op = row.operator("bim.layer_ui_select", icon="ZOOM_SELECTED", text="") + op.layer_id = active_item.layer_id row.prop(props, "is_editing_item_layer", icon="GREASEPENCIL", text="") if layer: row.operator("bim.unassign_representation_item_layer", icon="X", text="") diff --git a/src/bonsai/bonsai/bim/module/layer/__init__.py b/src/bonsai/bonsai/bim/module/layer/__init__.py index 95ce31c8cc..9ee1c57fb4 100644 --- a/src/bonsai/bonsai/bim/module/layer/__init__.py +++ b/src/bonsai/bonsai/bim/module/layer/__init__.py @@ -27,6 +27,7 @@ classes = ( operator.EditPresentationLayer, operator.EnableEditingLayer, operator.LoadLayers, + operator.SelectLayerInLayerUI, operator.RemovePresentationLayer, operator.SelectLayerProducts, operator.UnassignPresentationLayer, diff --git a/src/bonsai/bonsai/bim/module/layer/operator.py b/src/bonsai/bonsai/bim/module/layer/operator.py index 5cc0797699..9c2f4a2249 100644 --- a/src/bonsai/bonsai/bim/module/layer/operator.py +++ b/src/bonsai/bonsai/bim/module/layer/operator.py @@ -190,3 +190,22 @@ class SelectLayerProducts(bpy.types.Operator): if element and element in elements: obj.select_set(True) return {"FINISHED"} + + +class SelectLayerInLayerUI(bpy.types.Operator): + bl_idname = "bim.layer_ui_select" + bl_label = "Select Layer In Layers UI" + bl_options = {"REGISTER", "UNDO"} + layer_id: bpy.props.IntProperty() + + def execute(self, context): + props = tool.Layer.get_layer_props() + ifc_file = tool.Ifc.get() + layer = ifc_file.by_id(self.layer_id) + bpy.ops.bim.load_layers() + props.active_layer_index = next((i for i, m in enumerate(props.layers) if m.ifc_definition_id == self.layer_id)) + self.report( + {"INFO"}, + f"Layer '{layer.Name or 'Unnamed'}' is selected in Layers UI.", + ) + return {"FINISHED"}