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
context = bpy.context # only selected items
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"
mesh_objs = [ob for ob in context.selected_objects if ob.type == 'MESH']
print("Materials in scene")
for mesh in mesh_objs:
if mesh.active_material is not None:
#print("active_material:", repr(mesh.active_material) )
for materialSlot, mat in enumerate(mesh.material_slots):
if not materialSlot:
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)
newMaterial = bpy.data.materials.get(desiredMaterialName)
if newMaterial is not None:
mesh.material_slots[materialSlot].material = newMaterial
print("No equivalent Material found for ", desiredMaterialName)
elif (mat.name.find(DesiredMaterialNamePrefix) != -1):
print("Found Desired Renderer: ", DesiredMaterialNamePrefix)
print("No change necessary")
print("\t[%d] is None" % materialSlot)