1
$\begingroup$

So what I'm trying to do is use the "bpy.context.selected_objects" and get the material index from it somehow but I have no experience coding in python and I want to use that in "mat = (Here)" so I can then use "mat.diffuse_color" to change all the materials colors to the same color.

I know it's kinda like asking someone to write code for me but to me it only seems like I need help with 1 line and I don't want to learn a new language just to execute 1 script and likely never use it again. I just really need to change all the material colors because I have a large scene with over 1000 objects and all together there are over 250 materials so doing it manually is a very lengthy process as I have 8 more scenes similar to it.

Note: I can't make them the same material as they have textures applied to them.

$\endgroup$

2 Answers 2

5
$\begingroup$

You don't have to access the material index, since you have access to an object's active material. This will do what you're aiming for:

enter image description here

import bpy

r,g,b = (0.1, 0.5, 0.7) # Set color RGB value

# Iterate over all the selected objects
for o in bpy.context.selected_objects:
    # Set the active materials diffuse color to the specified RGB
    o.active_material.diffuse_color = (r,g,b)
$\endgroup$
0
-1
$\begingroup$

To set the material for many objects at once: apply the material to an object, then press control-L. This is a "link" menu. You can then link the material from the Active object to all the selected. This menu allows you to copy modifiers or even geometry from the active object to all selected.

$\endgroup$
1
  • $\begingroup$ Although this is true, the question asked specifically for a python solution that doesn't apply the same material to all the objects $\endgroup$
    – Nicola Sap
    Commented Sep 24, 2018 at 9:59

You must log in to answer this question.

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