maxdudik maxdudik - 3 years ago 97
Python Question

How to get Blender Compositor Image Node selected image name?

In what way my Python script can get text string with name of an image, currently selected in Image Node? I guess is right to do using custom Node Label, but can't find any snippet, which describes method.


Script must work globally, even if no any node selected, if possible.

Solution from Madlaina Kalunder:
Works globally and no need to select node, just give the name IMAGENODE and:['Scene'].node_tree.nodes['IMAGENODE']

Answer Source

Hope this helps you out:

    nodes = material_slot.material.node_tree.nodes
    texture_node = nodes.get('Image Texture')

    if texture_node is None:
        texture_node ='ShaderNodeTexImage')
        #texture_node.image = image

    # Get the image name
    texture_name =
    # Set the node name / label to image name = texture_name
    texture_node.label = texture_name

if you want to get an existing node but you have multiple Texture Nodes, you could probably iterate trough all nodes and find all nodes of type "TEX_IMAGE" and set the name

EDIT: I have seen you just added a picture, and you are not working with textures, sorry about that Same principle as above goes for Image nodes though['Scene'].node_tree.nodes['Image']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download