I had a similar problem, so I cobbled together a quick script.
I like my final renders to be in cycles, but I like to work in Blender Internal. The script swaps materials on selected objects. All materials named Cycles.whatever or GLSL.whatever will be replaced with the one appropriate for the current rendering engine. Note, this doesn't make the materials for you, just swaps from one to the other.
Takes more time up front, because I have to make two sets of materials, but it saves me a lot of time in the project because Blender Internal is so much faster than cycles and looks better during modeling.
# This script should go through all the materials in the SELECTED objects and replace them with another material (that you made) who's name is prefixed with Cycles or GLSL accordingly
# Switch the renderer, select some objects, then run this script.
# You'll need two copies of every material, one for cycles and one for GLSL.
# Just name the materials CYCLES.whatever and GLSL.whatever
# eg: Cycles.black.glossy <-> GLSL.black.glossy
import bpy
context = bpy.context # only selected items
print(bpy.data.scenes["Scene"].render.engine)
RenderEngine = bpy.data.scenes["Scene"].render.engine
if RenderEngine == "BLENDER_GAME" or RenderEngine == "BLENDER_RENDER":
DesiredMaterialNamePrefix = "GLSL"
UndesiredMaterialNamePrefix = "Cycles"
elif RenderEngine == "CYCLES":
DesiredMaterialNamePrefix = "Cycles"
UndesiredMaterialNamePrefix = "GLSL"
print("---------------------------------------")
mesh_objs = [ob for ob in context.selected_objects if ob.type == 'MESH']
print("Materials in scene")
print(dir(bpy.data.materials))
for mesh in mesh_objs:
print(repr(mesh))
print("active_slot:", mesh.active_material_index)
if mesh.active_material is not None:
#print("active_material:", repr(mesh.active_material) )
print("active_material:", mesh.active_material.name)
for materialSlot, mat in enumerate(mesh.material_slots):
if not materialSlot:
print("material_slots")
if mat is not None:
print("\t[%d] = %s" % (materialSlot, mat.name))
# figure out if the undesired renderer is in the material name
# if so, change the material to match the desired renderer
# (but verify that the material actually exists before you try to make the swap)
if (mat.name.find(UndesiredMaterialNamePrefix) != -1):
print("Found material: ", mat.name)
desiredMaterialName = mat.name.replace(UndesiredMaterialNamePrefix, DesiredMaterialNamePrefix)
print("Change to: ", desiredMaterialName)
print("finding material")
newMaterial = bpy.data.materials.get(desiredMaterialName)
if newMaterial is not None:
print(repr(newMaterial))
mesh.material_slots[materialSlot].material = newMaterial
#print(newMaterial.name)
else:
print("No equivalent Material found for ", desiredMaterialName)
elif (mat.name.find(DesiredMaterialNamePrefix) != -1):
print("Found Desired Renderer: ", DesiredMaterialNamePrefix)
print(repr(mat))
print("No change necessary")
else:
print("\t[%d] is None" % materialSlot)
print()