maxdudik maxdudik - 1 year ago 79
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.

Image

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:

bpy.data.scenes['Scene'].node_tree.nodes['IMAGENODE'].image.name

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 = nodes.new(type='ShaderNodeTexImage')
        #texture_node.image = image

    # Get the image name
    texture_name = texture_node.image.name
    # Set the node name / label to image name
    texture_node.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

bpy.data.scenes['Scene'].node_tree.nodes['Image'].image.name
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download