How to assign a specific color scale to all specific objects in the scene I have some meshes in the scene (7 mesh objects for example). I want to assign each object a color. The color should vary in a specific scale. For example: green scale. So, first object has green value 0.1, second 0.2 and so on. So in the end, I can able to see a pattern of color.

All this I want as a BoolProperty checkbox button in my UI Panel. So, when I check it, it should show me colors and vice versa.

def switch(self, context):
   bool = context.scene.bool
   objects = bpy.data.objects
   mat = bpy.data.materials['Material']
   if bool == True:
       print ("True")
       for ind, object in enumerate(bpy.context.scene.objects):
           mat = bpy.data.materials.new("BSDF")
           val = 0.0
           mat.diffuse_color = (float(val), 1, float(val))
           object[ind].active_material = mat 
           val += .1

    else:
        for ind, object in enumerate(bpy.context.scene.objects):
            object[ind].active_material.delete()


This is what I want to achieve but it's not working.
You only want to iterate thru mesh (or meta i suppose) objects that can have a material.  Here is a sample, changing scene.bool removes material if False, or adds a new material to each object with a differing shade of green.

import bpy
from bpy.props import BoolProperty

def toggle_bool(self, context):

    val = 0.0
    for o in self.objects:
        if o.type not in {'MESH', 'META'}:
            continue

        if self.bool:
            print(o, val)
            mat = bpy.data.materials.new("BSDF")
            mat.diffuse_color = (val, 1, val)

            o.active_material = mat
            val += 0.1
        else:
            o.active_material = None

bpy.types.Scene.bool = BoolProperty(update=toggle_bool)