← All ideas
  • Published 11 Oct 2024

Extrude "reroute node"

Recently I found myself rerouting a lot of nodes, and I think it would be very enjoyable to be able to press "E" to pop a new reroute node already connected to the first one.

100%

Development Status: Open

Upvote 11 Downvote 0
jablaya
11 Oct 2024

5 Comments

tche_adriano

Just had the same ideia.

MD3D

Hi all,

This is my first post here. I don't know if this is place to share scripts, but I think I have a solution. I wrote this script.

Select a reroute socket, CTRL+E (you can change it to whatever you want. In my case E was already taken) It wil execute Duplicate (Shift ,,+D), then after placed the duplicate on the canvas, it add the original socket to the selection. Then it wil execute Make Links (F) and finally it will de-select the original socket, leaving you with duplicated socket selected. And ready to execute the script again on the duplicated reroute socket.

 import bpy

class NODE_OT_duplicate_reroute_and_link(bpy.types.Operator):
    bl_idname = "node.duplicate_reroute_and_link"
    bl_label = "Duplicate Reroute and Link (Safe)"
    bl_options = {'REGISTER', 'UNDO'}

    old_node = None

    def modal(self, context, event):
        if event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
            tree = context.space_data.edit_tree  # ✅ Corrected line

            new_node = None
            for node in tree.nodes:
                if node.select and node.type == 'REROUTE' and node != self.old_node:
                    new_node = node
                    break

            if self.old_node and new_node:
                tree.links.new(self.old_node.outputs[0], new_node.inputs[0])
                self.old_node.select = False

            return {'FINISHED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        space = context.space_data
        if not space or space.type != 'NODE_EDITOR':
            self.report({'WARNING'}, "Not in node editor")
            return {'CANCELLED'}

        tree = space.edit_tree  # ✅ Corrected line
        if not tree:
            self.report({'WARNING'}, "No active node tree")
            return {'CANCELLED'}

        for node in tree.nodes:
            if node.select and node.type == 'REROUTE':
                self.old_node = node
                break
        else:
            self.report({'WARNING'}, "No reroute node selected")
            return {'CANCELLED'}

        bpy.ops.node.duplicate_move('INVOKE_DEFAULT')
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}

def register():
    bpy.utils.register_class(NODE_OT_duplicate_reroute_and_link)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = kc.keymaps.get('Node Editor')
        if not km:
            km = kc.keymaps.new(name='Node Editor', space_type='NODE_EDITOR')
        if not any(kmi.idname == NODE_OT_duplicate_reroute_and_link.bl_idname for kmi in km.keymap_items):
            km.keymap_items.new(NODE_OT_duplicate_reroute_and_link.bl_idname, 'E', 'PRESS', ctrl=True)

def unregister():
    bpy.utils.unregister_class(NODE_OT_duplicate_reroute_and_link)

if __name__ == "__main__":
    register()
thomas83

Did anyone suggest this in the blender survey?

thomas83

This could really speed things up

modormoder

There was idea about reroute extrude\