Change Viewport Display Color of selection/collection of objects - Only changing one Trying to make a simple script to change the viewport display colors of a selection of objects. (I like to keep track of things visually with color codes on objects.)
The script below will change the 'material color' of multiple objects, but will only change the Viewport Display color of the last selected object, which I've sussed out to be 'object color'
(Thanks for any tips, not much of a programmer at all)
import bpy

# 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 = (0.8, 0.1, 0.0, 1)
    bpy.context.object.color = (0.8, 0.1, 0.0, 1)
It's even simpler than that ! Replace the last line with :
o.color = (0.8, 0.1, 0.0, 1)

FYI, the for loop iterates over all selected objects in the viewport, pretty straightforward.
Then the second line changes the material viewport display color. This is what you see when you set the Solid view mode to &quot;Material&quot;. Be careful though, if your object doesn't have any active material, this will throw an error and terminate the script not so gracefully.

The last line is supposed to change the object viewport color, what you see when you set the mode to &quot;Object&quot;.
Your script only takes the active object in the viewport, the one with the yellow outline. You rather want to change the color of each selected object, noted o inside the for loop.