I have a few vertices selected and would like to change the colour of those vertices with Python script. This means adding a new material slot.
I have tried this script, however it changes all the vertices and not the ones selected.
activeObject = bpy.context.active_object #Set active object to variable
mat = bpy.data.materials.new(name="MaterialName") #set new material to variable
activeObject.data.materials.append(mat) #add the material to the object
bpy.context.object.active_material.diffuse_color = (0.121583, 0.144091, 0.8, 1)
bpy.context.object.data.polygons[0].material_index– sambler Jun 24 '19 at 08:49