10
$\begingroup$

I want to use Freestyle for a scene with lots of different Cycles Materials, is there an easy way to change them all at once to Blender Internal?

It would be nice if the materials are somehow related, but thats not that important. More important is, that if one material is used for two objects, afterwards the relation stays the same, having the material assigned to the objects as before and not to others (therefor just assigning one new bi material to all objects wouldnt work).

I know that switching the renderer to bi and unchecking "Use Nodes" in the material tab makes roughly what I want, but doing that manualy for every material one by one takes lots of time.

Is there a command or script that I can use?

$\endgroup$
1

2 Answers 2

9
$\begingroup$

Try running this in the text editor:

import bpy

for mat in bpy.data.materials:
    mat.use_nodes = False

It will disable use nodes for every material.

$\endgroup$
3
  • $\begingroup$ Typed it into the python console and works just perfect. Thanks a lot $\endgroup$ Jun 29, 2014 at 9:13
  • $\begingroup$ @user2567875 That works too. If you feel this answers your question, feel free to mark it as accepted :) $\endgroup$
    – gandalf3
    Jun 29, 2014 at 9:15
  • $\begingroup$ I tried, but had to wait several minutes before I was allowed to do so. Now done. $\endgroup$ Jun 29, 2014 at 9:20
1
$\begingroup$

I cobbled together a quick script to quickly swap all the materials on selected objects.

If a material is named GLSL.whatever, or Cycles.whatever, it'll switch it to whatever is appropriate for your currently selected render engine.

Note, this doesn't make the materials for you, just goes through the list and swaps materials named GLSL.materialName for Cycles.materialName or vice versa.

It's useful if you want to use GLSL (Blender Internal) for modeling, then switch to Cycles for major renders. It takes more time up front to make two materials instead of one, but it saves a ton of time during the project because you can preview your work in the realtime GLSL rendering engine.

(To use it, put it in a text window and hit alt-p to run the script, or just select run script from the text menu.)

(Disclaimer: I wrote it quickly and haven't thoroughly error checked it, so no guarantees. Try it on a test scene first. It works for me though.)

# 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()
$\endgroup$
1
  • $\begingroup$ interesting, this is basically an auto-toggle of materials between renderers right? but, it seems we could avoid creating duplicated materials as said here, I think this way it would only require disabling the material node option of all materials $\endgroup$ Jan 3, 2016 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .