I would like to pre-define a material for a grease pencil in an addon. However, when a new material is created from python, it is not a grease pencil material (mat.is_grease_pencil = False). It is not possible to set the mat.grease_pencil.color of this material, because this part of the data structure does not exist, etc.
What is the python equivalent of clicking the "New (add a new material)" button when a grease pencil object is active?
# Create a grease pencil object
bpy.ops.object.gpencil_add(type='EMPTY')
bpy.ops.object.mode_set(mode='PAINT_GPENCIL')
gp_obj = bpy.data.objects['GPencil']
bpy.context.view_layer.objects.active = gp_obj
# Create a net material
gp_mat = bpy.data.materials.new("my_gp_material") # This is not a grease pencil material
gp_mat.grease_pencil.color = [0,1,0,1] # This is not possible, as mat.grease_pencil is None
gp_obj.data.materials.append(gp_mat) # Trying to draw after this will crash Blender
Thanks for your help!