Set material color to white

Hello,
I want to make the all materials color to white. (only Principled BSDF)
I found the code but it not worked.
Is there any addon or hints?
thank you :slight_smile:

import bpy

C = bpy.context

for i in range(0,len(C.object.material_slots)):
    C.object.active_material_index = 1
    bpy.ops.object.diffuse_color = (1,1,1)

bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_all(action = 'SELECT')
bpy.ops.object.material_slot_assign()
bpy.ops.object.mode_set(mode = 'OBJECT')

In the “Layer Properties” tab you can set an override material that will apply to all the objects in the View Layer (in 2.8.x at least)

Hi sir, Thank you! :slight_smile:
But I want to keep each texture image.
It is setup for baking texture.

Oh, I see, I misunderstood your question. Never mind!

1 Like
import bpy

# all materials
for m in bpy.data.materials:
    
    # not grease pencil
    if m.is_grease_pencil: continue

    # all nodes
    for n in m.node_tree.nodes:
        
        # only bsdf
        if n.type == 'BSDF_PRINCIPLED':
            
            # base color
            c = n.inputs['Base Color']
            print('color of', m.name, 'is', list(c.default_value))
            
            # change
            c.default_value = [1.0, 1.0, 1.0, 1.0]
            
            
            
            # to next material
            break
1 Like

Hey Pati,
I use a custom group node for this. The advantage of a group node is that switching from white to color can be set once, tabbing into the group node, affecting all materials that have it in the node structure, all at once (… could be hundreds). For this purpose you want the switch (fac= 0/1) inside the group, not as a node variable input.
Usually I place this node just before the color input of the Principled shader (but could be BSDF or other shader). An example of putting it further away from the output is if you want to mix AO occlusion (which looks good on white) The channels that handle normals, roughness, bump, etc are unaffected.

The following link to a thread is a project of a house I presented this way, in “white clay”, because I did not want the client to get caught up in material details at this stage - it was preliminary design at the time. All materials of the house are textured (and transparent where relevant) but white, while the scenery is simple abstract but colored. One click to flip the house to color (fac=0).

This is the node setup, fac=1 means turn on white clay, fac=0 color
image

The following is a usage example (here set before mix with AO) :

1 Like

Thank you sir! It worked well. I learned a lot :slight_smile:

1 Like

Thank you sir! It is great detail. I didn’t know the group node. It looks so super useful :slight_smile:
I recently came to Blender. It so powerful…

It is extremely powerful and broad in scope, which makes it somewhat complicated, though the changes in interface since 2.8 have helped make it more clear and friendly. Great software for any price.

Welcome to the Blender community.
Where are you from? and what profession? 3D artist, architect, animator, amateur?

1 Like

That’s nice work! And what was the modeling software for the artwork in the reel?

1 Like

Thank you! But not there yet :sweat_smile:
I used rayfire and tyflow and zbrush(asset) for destruction modeling. Also used kitbash sometimes.
Simulation is almost tyflow.

But there are feel limit. So recently, I am studying Houdini too. To get unlimited expression :slight_smile:
Blender and Houdin are the CGI’s mainstream in the future!

This is top level stuff there. I need to see more. :slight_smile:

1 Like

Hi sir, Thank you for kind words :slight_smile:
I’ll continue to do my best to create good content!

1 Like