I'm making a motion graphics. All elements (in hundreds) are modeled in diffuse and have different colours. How do I select them all and change to emission shader without affecting the colors?

• You can change node type with Node Wrangler addon, if it's enabled press Shift+S with node selected and choose node to change to. But that will change for one material. Maybe scripting is the best way for multiple. – Mr Zak May 14 '17 at 11:52

This script from http://web.purplefrog.com/~thoth/blender/python-cookbook/change-diffuse-to-emission-node.html should work

import bpy

def replace_with_emission(node, node_tree):
connected_sockets_out = []
sock = node.inputs[0]
else:
defaults_in = sock.default_value[:]

for sock in node.outputs:
else:
connected_sockets_out.append(None)

#print( defaults_in )

new_node.location = (node.location.x, node.location.y)

new_node.inputs[0].default_value = defaults_in

if connected_sockets_out[0] is not None:

def material_diffuse_to_emission(mat):

doomed=[]
for node in mat.node_tree.nodes:
if node.type=='BSDF_DIFFUSE':
replace_with_emission(node, mat.node_tree)
doomed.append(node)

# wait until we are done iterating and adding before we start wrecking things
for node in doomed:
mat.node_tree.nodes.remove(node)

def replace_on_selected_objects():
mats = set()
for obj in bpy.context.scene.objects:
if obj.select:
for slot in obj.material_slots:

for mat in mats:
material_diffuse_to_emission(mat)

def replace_in_all_materials():
for mat in bpy.data.materials:
material_diffuse_to_emission(mat)

if True:
replace_on_selected_objects()
else:
replace_in_all_materials()


Just paste a copy into a blender Text Editor, select the objects you want adjusted, and click the Run Script button. If you want to rework all the materials, just change the tail end of the script to run the replace_in_all_materials() function.