From cca8cfcb8d76286e52d6a3ceb8b3f8cd2828a6f6 Mon Sep 17 00:00:00 2001 From: "1029920178@qq.com" <1029910278@qq.com> Date: Sat, 3 Aug 2024 21:54:09 +0800 Subject: [PATCH] fix: remove layer report error when no layer --- bl_operator/ops_gp_basic.py | 3 ++- model/model_gp.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bl_operator/ops_gp_basic.py b/bl_operator/ops_gp_basic.py index e74be9d..9ccb1ef 100644 --- a/bl_operator/ops_gp_basic.py +++ b/bl_operator/ops_gp_basic.py @@ -47,7 +47,8 @@ def poll(cls, context): def execute(self, context): nt: bpy.types.NodeTree = context.space_data.edit_tree gp_data: bpy.types.GreasePencil = nt.grease_pencil - if not gp_data: return {'CANCELLED'} + if not gp_data: + return {'CANCELLED'} with BuildGreasePencilData(gp_data) as gp_data_builder: if SelectedGPLayersRuntime.selected_layers(): for layer in SelectedGPLayersRuntime.selected_layers(): diff --git a/model/model_gp.py b/model/model_gp.py index 375f0f1..a89561f 100644 --- a/model/model_gp.py +++ b/model/model_gp.py @@ -222,11 +222,12 @@ def remove_active_layer(self) -> 'BuildGreasePencilData': def remove_layer(self, layer_name_or_index: str | int) -> 'BuildGreasePencilData': """Remove the grease pencil annotation layer.""" - if not (layer := self._get_layer(layer_name_or_index)): return self - - index = self.gp_data.layers.find(layer.info) - self.gp_data.layers.remove(layer) try: + if not (layer := self._get_layer(layer_name_or_index)): return self + + index = self.gp_data.layers.find(layer.info) + self.gp_data.layers.remove(layer) + next_layer = self.gp_data.layers[index - 1] if not self.edit_layer.is_in_2d(next_layer): self.edit_layer.display_in_3d(next_layer)