From 60f804482055db126028f7e809291949b60ff1b7 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 24 Jan 2025 15:43:18 +0500 Subject: [PATCH] Support adding IfcPresentationLayerWithStyle from UI Example - https://i.imgur.com/0mssU2s.png --- src/bonsai/bonsai/bim/module/layer/operator.py | 10 ++++++++-- src/bonsai/bonsai/bim/module/layer/prop.py | 9 +++++++++ src/bonsai/bonsai/bim/module/layer/ui.py | 13 ++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/layer/operator.py b/src/bonsai/bonsai/bim/module/layer/operator.py index c633b50315..a35421636a 100644 --- a/src/bonsai/bonsai/bim/module/layer/operator.py +++ b/src/bonsai/bonsai/bim/module/layer/operator.py @@ -81,12 +81,18 @@ class DisableEditingLayer(bpy.types.Operator): class AddPresentationLayer(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_presentation_layer" bl_label = "Add Layer" + bl_description = "Add new presentation layer." bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - result = ifcopenshell.api.run("layer.add_layer", IfcStore.get_file()) + props = context.scene.BIMLayerProperties + ifc_file = tool.Ifc.get() + if props.layer_type == "IfcPresentationLayerWithStyle": + layer = ifcopenshell.api.layer.add_layer_with_style(ifc_file) + else: + layer = ifcopenshell.api.layer.add_layer(ifc_file) bpy.ops.bim.load_layers() - bpy.ops.bim.enable_editing_layer(layer=result.id()) + bpy.ops.bim.enable_editing_layer(layer=layer.id()) return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/layer/prop.py b/src/bonsai/bonsai/bim/module/layer/prop.py index 335e23272e..f8bea1a4dd 100644 --- a/src/bonsai/bonsai/bim/module/layer/prop.py +++ b/src/bonsai/bonsai/bim/module/layer/prop.py @@ -42,3 +42,12 @@ class BIMLayerProperties(PropertyGroup): layers: CollectionProperty(name="Layers", type=Layer) active_layer_index: IntProperty(name="Active Layer Index") is_editing: BoolProperty(name="Is Editing", default=False) + layer_type: EnumProperty( + name="Presentation Layer Type", + description="Presentation layer type to add", + items=( + ("IfcPresentationLayerAssignment", "IfcPresentationLayerAssignment", ""), + ("IfcPresentationLayerWithStyle", "IfcPresentationLayerWithStyle", ""), + ), + default="IfcPresentationLayerAssignment", + ) diff --git a/src/bonsai/bonsai/bim/module/layer/ui.py b/src/bonsai/bonsai/bim/module/layer/ui.py index ae1bcc430c..383fb671a4 100644 --- a/src/bonsai/bonsai/bim/module/layer/ui.py +++ b/src/bonsai/bonsai/bim/module/layer/ui.py @@ -43,12 +43,15 @@ class BIM_PT_layers(Panel): self.props = context.scene.BIMLayerProperties row = self.layout.row(align=True) - row.label(text=f"{LayersData.data['total_layers']} Layers Found") - if self.props.is_editing: - row.operator("bim.add_presentation_layer", text="", icon="ADD") - row.operator("bim.disable_layer_editing_ui", text="", icon="CANCEL") - else: + row.label(text=f"{LayersData.data['total_layers']} Layers Found", icon="STICKY_UVS_LOC") + if not self.props.is_editing: row.operator("bim.load_layers", text="", icon="GREASEPENCIL") + return + + row.operator("bim.disable_layer_editing_ui", text="", icon="CANCEL") + row = self.layout.row(align=True) + row.prop(self.props, "layer_type", text="") + row.operator("bim.add_presentation_layer", text="", icon="ADD") if self.props.is_editing: self.layout.template_list(