Adding a new material to a grease pencil I have added a grease pencil and need to add a new material slot in python. I have used this script for active objects, however I am missing something with the grease pencil.

activeObject = bpy.context.active_object 
mat = bpy.data.materials.new(name="MaterialName") 
activeObject.data.materials.append(mat)

bpy.context.object.active_material.diffuse_color = (0.121583, 0.144091, 0.8, 0.729885)
The script below enables you to add a new material slot for your active grease pencil.

import bpy

ob = bpy.context.active_object  # Must be a GPencil object
mat = bpy.data.materials.new(name="Mymaterial")
bpy.data.materials.create_gpencil_data(mat)
ob.data.materials.append(mat)