i'm trying to do an automated naming system for my file outputs in blender compositor, i want the file output input's socket to get the name of the input of their respective links. I'm not really getting how (new in python). So far my script looks like

import bpy
import os

# Get absolute path:
filepath = bpy.context.scene.render.filepath
absolutepath = bpy.path.abspath(filepath)

# Split it
path = os.path.normpath(absolutepath)
parts = path.split(os.sep)

absolutepath = os.sep.join(parts[:-2])

# Get name of th input
name01 = bpy.data.node_groups["CYCLES MULTIPASS CREATION"].outputs[0].name

# set the path for all file output nodes:
for scene in bpy.data.scenes:
    for node in scene.node_tree.nodes:

        if node.type == 'OUTPUT_FILE':
            node.base_path = absolutepath
            node.file_slots[0].path = "\_shadow\_" + "nom" + "_" + name01

But this is "absolute" version of what i'm trying to do, the input socket name is not relative to the output socket name of the previous node... Somebody has an idea ? thank you very much !


1 Answer 1


To get the name of the socket a node's input is linked to:

#using the File output node from your example
link = node.inputs[0].links[0] #gets the link from the input
socket_name = link.from_socket.name #returns the name of the socket the link is from
  • $\begingroup$ thanks man ! it works, but i have to input the socket number ( [0] ) every time, is it possible to just tell blender to get the right one, depending on the output one ? $\endgroup$
    – tonton
    Jan 5, 2017 at 17:23
  • $\begingroup$ I don't quite understand. $\endgroup$
    – cmomoney
    Jan 5, 2017 at 17:44
  • $\begingroup$ i mean is it possible to just put something like link = node.inputs.links[0] without an imput number to get something applyable to all the input immediatly ? $\endgroup$
    – tonton
    Jan 5, 2017 at 17:56
  • $\begingroup$ inputs is a list of inputs so you have to designate which one, even if there's only one. $\endgroup$
    – cmomoney
    Jan 5, 2017 at 19:35
  • $\begingroup$ ok i see, the only inconvenient is to not be able to use a file output node with multiple input, not a real problem thank you very much for your quick answer ! $\endgroup$
    – tonton
    Jan 6, 2017 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .