69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
|
import bpy
|
||
|
from . import fn
|
||
|
|
||
|
|
||
|
class GPEXP_OT_reconnect_render_layer(bpy.types.Operator):
|
||
|
bl_idname = "gp.reconnect_render_layer"
|
||
|
bl_label = "Reconnect Render Layer"
|
||
|
bl_description = "Reconnect selected render layers"
|
||
|
bl_options = {"REGISTER"}
|
||
|
|
||
|
@classmethod
|
||
|
def poll(cls, context):
|
||
|
return True
|
||
|
|
||
|
# mode : bpy.props.StringProperty(default='NORMAL', options={'SKIP_SAVE'})
|
||
|
|
||
|
def execute(self, context):
|
||
|
node_tree = context.scene.node_tree
|
||
|
nodes = node_tree.nodes
|
||
|
|
||
|
changed = []
|
||
|
for n in nodes:
|
||
|
if not n.select or not n.type == 'R_LAYERS':
|
||
|
continue
|
||
|
|
||
|
if not ' / ' in n.layer:
|
||
|
continue
|
||
|
|
||
|
if n.outputs[0].is_linked: # already connected
|
||
|
continue
|
||
|
|
||
|
# get namme
|
||
|
obname = n.layer.split()[0]
|
||
|
grp_name = f'NG_{obname}'
|
||
|
|
||
|
|
||
|
# get nodegroup
|
||
|
grp = nodes.get(grp_name)
|
||
|
if not grp:
|
||
|
print(f'{n.name} Node group not found : {n.layer} !-> {grp_name}')
|
||
|
continue
|
||
|
|
||
|
inp = grp.inputs.get(n.layer)
|
||
|
if not inp:
|
||
|
print(f'{n.name} no inputs name "{n.layer}" in group {grp_name}')
|
||
|
continue
|
||
|
|
||
|
# reconnect
|
||
|
node_tree.links.new(n.outputs[0], inp)
|
||
|
changed.append(f'{n.name} ({n.layer}) to {grp_name}')
|
||
|
|
||
|
if changed:
|
||
|
self.report({'INFO'}, f'{len(changed)} nodes reconnected')
|
||
|
else:
|
||
|
self.report({'WARNING'}, f'Could not reconnect, see console')
|
||
|
|
||
|
return {"FINISHED"}
|
||
|
|
||
|
classes=(
|
||
|
GPEXP_OT_reconnect_render_layer,
|
||
|
)
|
||
|
|
||
|
def register():
|
||
|
for cls in classes:
|
||
|
bpy.utils.register_class(cls)
|
||
|
|
||
|
def unregister():
|
||
|
for cls in reversed(classes):
|
||
|
bpy.utils.unregister_class(cls)
|