How to paint vertices in different object using python scripts?
As far as I understand, this line

bpy.ops.object.mode_set(mode='VERTEX_PAINT')


only causes the user interface to switch to Vertex Paint mode, which displays the vertex colors in the viewport when the object is active and allows you to paint the vertices on your own. This step is not required if you color the vertices in a script and it does not change the way the final image is being rendered. If these colors should also appear in the final render then you have to set up your material to take vertex colors into account. The answer to this question describes how to do that if you're using the Cycles render engine. You should end up with a material like this:



Unless you're using an Emission shader instead of the Diffuse BSDF you still have to use other light sources in the scene.

And while the script seems to define the random_color function, the function doesn't actually get called. As you ended up with some parts of your model being painted, I assume this is only a missed line when you copied your script. In case it isn't, the last loop should probably be:



for obj in bpy.data.objects:
    if obj.type == 'MESH':
        bpy.context.scene.objects.active = obj
        bpy.ops.object.mode_set(mode='VERTEX_PAINT')
        random_color(obj)


It's likely that the viewport will still display only one mesh colored as Blender will only display vertex colors for the active object. All other objects will be displayed according to the Viewport Shading setting. This should explain why only one part of your model is colored while the rest of it remains grey. Once you've set up your material you can switch to Material shading to see the other parts of the plane colored as well.