Change diffuse color for all selected objects in scene with python
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:



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)