# Is it possible to set all texture nodes in a node tree to a specific vector?

Is there a way to automatically set selected nodes to use a specific vector input?

E.g. If you have a larger node setup with a lot of texture nodes, it can be a pain to go back through and connect each texture node's vector input to a texture coordinate node individually.

Is there a way to automate this process?

Add a Reroute node with the desired value and select it. Then, you can use this script.

# First, define some stuff
# mat: the material; tree: the node tree; nodes: the node list
mat = bpy.data.materials['Material Name'] # or index
tree = mat.node_tree
nodes = tree.nodes

# We'll find the source node and store it in src
src_socket = None
if nodes.active:
if len(nodes.active.outputs) == 1:
src_socket = nodes.active.outputs[0]

if src_socket is not None:                       # only work if node found
for node in nodes:                             # check each node
if node.type.startswith('TEX'):              # only operate on textures
for input in node.inputs:                  # check each input
if input.type == 'VECTOR':               # only operate on vectors
break                                  # only do the first vector
else:                                            # fail if no valid select
print('No single-output node selected')


Tested on Blender v2.69 r60995.

• Instead of that first loop to assign src to the node, could you instead use src = nodes['CopyVector']? (using a try/except incase it doesn't exist) – Greg Zaal Nov 12 '13 at 5:54
• @GregZaal Good point, thanks - but see my edit; this is easier anyway. – wchargin Nov 12 '13 at 5:54
• Well there's always a better solution isn't there ;) – Greg Zaal Nov 12 '13 at 5:55
• There is a reference to an undefined variable src on line 13. I changed it to src_socket and it worked beautifully. Also, if anyone copy/pastes this they won't import bpy, you might want to add that. Thanks :) – gandalf3 Nov 13 '13 at 8:07
• @gandalf3 fix'd. – wchargin Nov 16 '13 at 1:00