I'm using the Blender to make all my works university (architecture), but in my job the people use Sketchup for modeling and V-Ray for rendering. I want use Blender, cause liked more then others, the problem is that to rendering with Cycles, I have to need import the Skp file, change all materials (or set), create lamps etc... How to make a Python script that replace the materials by one list in all objects on the scene?

For example:

  • Cube.001 have the material "OldMaterial.01" in one face, and "OldMaterial.02" in others.

  • Cube.002 have the material "OldMaterial.02" in one face, and "OldMaterial.03" in others.

And we have the list:

  • For "OldMaterial.01", replace to "NewMaterial.01"
  • For "OldMaterial.02", replace to "NewMaterial.02"
  • For "OldMaterial.03", replace to "NewMaterial.03"

And the script replace all materials for the match in the list.

That will be increase so much the workflow Sketchup - Blender!

Thanks for now!


Every object has a list of materials it uses in it's material_slots property, this is shown in the material properties, each slot contains the material used. By looping through this list you can change the material assigned to each slot.

I would setup a dictionary of old-to-new names to use for the conversion process.

import bpy

matnames = {
    'OldMaterial.01': 'NewMaterial.01',
    'OldMaterial.02': 'NewMaterial.02',
    'OldMaterial.03': 'NewMaterial.03',
    'OldMaterial.04': 'NewMaterial.04',
    'OldMaterial.05': 'NewMaterial.05',
    'OldMaterial.06': 'NewMaterial.06',

for obj in bpy.data.objects:
    for slot in obj.material_slots:
        slot.material = bpy.data.materials[matnames[slot.material.name]]
  • $\begingroup$ Nice! I'm new Python's user, and don't know programing :( But I trying to learn :D Thanks for all. But i have so many questions more hahahahhaa I try run this script that u posted, but don't worked :/ In the line "matnames = { .....}" u are creanting a dictionary, right? $\endgroup$ – Asaph Coimbra Fagundes Sep 16 '17 at 16:01
  • $\begingroup$ A good start would be spending an hour or two doing a getting started tutorial like the official python tutorial. Yes matnames is a dictionary, it uses the name of the old mat as the key to retrieve the name of the new mat. Everything between {} is the contents of the dictionary, adjust the old name and new name on each line to match what you have. $\endgroup$ – sambler Sep 17 '17 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.