From 85a42939ca121ded898703348a452d27992a52ba Mon Sep 17 00:00:00 2001 From: "christophe.seux" Date: Fri, 6 Sep 2024 17:55:04 +0200 Subject: [PATCH] Restore the layer state operator --- OP_setup_layers.py | 33 +++++++++++++++++++++++++++++++++ ui.py | 6 +++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/OP_setup_layers.py b/OP_setup_layers.py index 2b190cc..ff40820 100644 --- a/OP_setup_layers.py +++ b/OP_setup_layers.py @@ -161,6 +161,37 @@ class GPEXP_OT_export_infos_for_compo(bpy.types.Operator): return {"FINISHED"} + +class GPEXP_OT_restore_layers_state(bpy.types.Operator): + bl_idname = "gp.restore_layers_state" + bl_label = "Restore Layers State " + bl_description = "Restore original state of layers" + bl_options = {"REGISTER"} # , "UNDO" + + def execute(self, context): + layers_info_path = Path(bpy.data.filepath).parent / 'render' / 'infos.json' + if not layers_info_path.exists(): + self.report({"ERROR"}, 'No Info Found') + return {"CANCELLED"} + + layers_info = json.loads(layers_info_path.read_text(encoding='utf-8')) + + pool = [o for o in context.scene.objects if o.type == 'GPENCIL' and fn.is_valid_name(o.name)] + for gp in pool: + for layer_name, info in layers_info.items(): + if gp.name == info['object']: + if not (layer := gp.data.layers.get(layer_name)): + return + + if "opacity" in info: + layer.opacity = info['opacity'] + + if "blend_mode" in info: + layer.blend_mode = info['blend_mode'] + + return {"FINISHED"} + + class GPEXP_OT_layers_state(bpy.types.Operator): bl_idname = "gp.layers_state" bl_label = "Set Layers State" @@ -335,6 +366,7 @@ class GPEXP_OT_layers_state(bpy.types.Operator): return {"FINISHED"} + class GPEXP_OT_lower_layers_name(bpy.types.Operator): bl_idname = "gp.lower_layers_name" bl_label = "Normalize Layers Name" @@ -643,6 +675,7 @@ classes=( GPEXP_OT_auto_number_object, GPEXP_OT_lower_layers_name, GPEXP_OT_export_infos_for_compo, +GPEXP_OT_restore_layers_state, GPEXP_OT_layers_state, GPEXP_OT_check_masks, GPEXP_OT_select_layer_in_comp, diff --git a/ui.py b/ui.py index 3465bd1..58f646c 100644 --- a/ui.py +++ b/ui.py @@ -274,7 +274,11 @@ class GPEXP_PT_gp_dopesheet_ui(Panel): row.operator('gp.auto_number_object', icon='X', text='').delete = True col.operator('gp.lower_layers_name', icon='SYNTAX_OFF', text='Rename Lowercase') col.operator('gp.export_infos_for_compo', icon='FILE', text='Export Layers Infos') # Not really need, called in Check layers invoke - col.operator('gp.layers_state', icon='CHECKMARK', text='Check layers') + + row = layout.row(align=True) + row.operator('gp.layers_state', icon='CHECKMARK', text='Check layers') + row.operator('gp.restore_layers_state', icon='DECORATE_OVERRIDE', text='') + col.operator('gp.check_masks', icon='MOD_MASK', text='Has Masks') # row = layout.row()