How to refer to an image by it's label name (Python) I want to create a function that will link from a node that has already been created and connect it to one I have just made. In my case, I want to have a Texture Coordinate and whenever I run this function, it will connect the TexCoord's UV output to a new image texture's Vector input.

I can label the node using 

&lt;!-- language: lang-py --&gt;
#Convenience variables 
nt = mat.node_tree
nodes = nt.nodes

texCoord = nodes.new("ShaderNodeTexCoord").label = "Master Vector"


It successfully labels the node, but I'm not sure how to use that information in order to call it later on.

Also at this point, when I label it this way it stops playing nice with the rest of my code.

Full code:

import bpy
mat_name = bpy.context.active_object.active_material.name
image_path = "E:\\PBRTest Folder\\example_AO.png"

mat = (bpy.data.materials.get(mat_name) or
       bpy.data.materials.new(mat_name))

mat.use_nodes = True
nt = mat.node_tree
nodes = nt.nodes
links = nt.links

# clear all other nodes
while(nodes): nodes.remove(nodes[0])

output  = nodes.new("ShaderNodeOutputMaterial")
diffuse = nodes.new("ShaderNodeBsdfDiffuse")
texture = nodes.new("ShaderNodeTexImage")
texCoord = nodes.new("ShaderNodeTexCoord").label = "Master Vector"
mapping = nodes.new("ShaderNodeMapping")

texture.image = bpy.data.images.load(image_path)

links.new( output.inputs['Surface'], diffuse.outputs['BSDF'])
links.new(diffuse.inputs['Color'],   texture.outputs['Color'])
links.new(texture.inputs['Vector'], mapping.outputs['Vector'])
links.new(mapping.inputs['Vector'], texCoord.outputs['UV'])
#links.new(texture.inputs['Vector'],    uvmap.outputs['UV'])
# distribute nodes along the x axis
for index, node in enumerate((texCoord, mapping, texture, diffuse, output)):
    if node == mapping:
        node.location.x = 200.0 * index
    else:
        node.location.x = 300.0 * index
If that is going to be the only texture coordinate node in the tree something like this might be adequate:

import bpy

mat = bpy.data.materials[0]

tcs = [ node for node in mat.node_tree.nodes if node.bl_idname=="ShaderNodeTexCoord"]
# python list comprehension filters the list of nodes down to the ones that match the right bl_idname

tcnode = tcs[0]
# grab the first node of the one(s) that match the bl_idname