gp_render/OP_manage_outputs.py

75 lines
2.3 KiB
Python

import bpy
class GPEXP_OT_mute_toggle_output_nodes(bpy.types.Operator):
bl_idname = "gp.mute_toggle_output_nodes"
bl_label = "Mute Toggle output nodes"
bl_description = "Mute / Unmute all output nodes"
bl_options = {"REGISTER"}
mute : bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'})
def execute(self, context):
# scene = bpy.data.scenes.get('Render')
ct = 0
for n in context.scene.node_tree.nodes:
if n.type != 'OUTPUT_FILE':
continue
n.mute = self.mute
ct += 1
state = 'muted' if self.mute else 'unmuted'
self.report({"INFO"}, f'{ct} nodes {state}')
return {"FINISHED"}
class GPEXP_OT_set_output_node_format(bpy.types.Operator):
bl_idname = "gp.set_output_node_format"
bl_label = "Set output format from active"
bl_description = "Change all selected output node to match active output node format"
bl_options = {"REGISTER"}
mute : bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'})
def execute(self, context):
# scene = bpy.data.scenes.get('Render')
nodes = context.scene.node_tree.nodes
if not nodes.active or nodes.active.type != 'OUTPUT_FILE':
self.report({"ERROR"}, f'Active node should be an output file to use as reference for output format')
return {"CANCELLED"}
ref = nodes.active
color_mode = ref.format.color_mode
file_format = ref.format.file_format
color_depth = ref.format.color_depth
compression = ref.format.compression
ct = 0
for n in context.scene.node_tree.nodes:
if n.type != 'OUTPUT_FILE' or n == ref:
continue
n.format.color_mode = color_mode
n.format.file_format = file_format
n.format.color_depth = color_depth
n.format.compression = compression
ct += 1
# state = 'muted' if self.mute else 'unmuted'
self.report({"INFO"}, f'{ct} output format copied from {ref.name}')
return {"FINISHED"}
classes=(
GPEXP_OT_mute_toggle_output_nodes,
GPEXP_OT_set_output_node_format,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)