Restore the layer state operator

main
christophe.seux 2024-09-06 17:55:04 +02:00
parent 734714be09
commit 85a42939ca
2 changed files with 38 additions and 1 deletions

View File

@ -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,

6
ui.py
View File

@ -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()