change object color for selected objects

Hi.
I am new to Blender.
I foud a world map made in blender on the internet.
I want to be able to change color for all the countries in Europe.
In my blender file, in Outliner, you will see all the curves.
I renamed 2 curves ( 2 countries), and triend to change their collor.
A print screen:


Here is the code i am tring to use :

import bpy

def makeMaterial(name, diffuse, specular, alpha):
mat = bpy.data.materials.new(name)
mat.diffuse_color = diffuse
mat.diffuse_shader = ‘LAMBERT’
mat.diffuse_intensity = 1.0
mat.specular_color = specular
mat.specular_shader = ‘COOKTORR’
mat.specular_intensity = 0.5
mat.alpha = alpha
mat.ambient = 1
return mat

scene = bpy.context.scene

for ob in scene.objects:
if ob.type == ‘MESH’ and ob.name.startswith(“Last”):
ob.select = True
#if i write : print(ob.name), i will see in the console the name of the 2 curves.
print(ob.name)

    def  setMaterial(ob,  mat):
        me  =  ob.data
        me.materials.append(mat)
       
    red  =  makeMaterial( 'NewMat' ,(1,0,0), (1, 1, 1), 0.5)
    setMaterial(ob, red)  

Please give me a hint.

I also found a script :

import bpy

for item in bpy.data.materials:
#Enable “use_shadeless”
item.use_shadeless = True
#Set the material Emit value to 1
item.emit = 1

#Change diffuse color 
item.diffuse_color = (1,0,1)


#Change diffuse shader to toon
item.diffuse_shader = 'TOON'
item.use_transparency = True
item.transparency_method = 'RAYTRACE'

but this changes the color for all my curves.

Can it be modified so it will change color for example, for all countries in North America?

can you elaborate a little !
how many curves do u have or meshes are there

look at your script

if ob.type == ‘MESH’ and ob.name.startswith(“Last”):

this is not looking for curves

only for mesh type !

also if u use the last part of script shown
it will change the color of all objects !

for the first part of you script u did not call the function to change color!

happy bl

WorldMapTest.blend (7.95 MB)

All the coutries are named Curves.

I tried to rename the last 2 countries from the list, and tried to change only their color.
This python thing drives me crazy.
I’m new to this but i have to solve it for a project at work.

In attach you will find the blend file.

thanks

Solved:
A little bit hardcoded, but from now an it is just some minor adjustments

import bpy

scene = bpy.context.scene

for ob in scene.objects:
if ob.type == ‘MESH’ and ob.name.startswith(“Africa”):
ob.select = True
bpy.context.scene.objects.active = ob
bpy.ops.object.mode_set(mode = ‘EDIT’)
bpy.context.object.active_material.diffuse_color=(1,1,1)
bpy.ops.object.mode_set(mode = ‘OBJECT’)

elif ob.type == 'MESH' and ob.name.startswith("Europa"):
    ob.select = True
    bpy.context.scene.objects.active = ob
    bpy.ops.object.mode_set(mode = 'EDIT') 
    bpy.context.object.active_material.diffuse_color=(0,1,0)
    bpy.ops.object.mode_set(mode = 'OBJECT')

not certain why you did this with a script
it is faster to do it manually !

you may have ob name = curve

but all these are mesh objects not curve objects

let us know if you need anything else

happy bl