Based on How to add points to a grease pencil stroke (or make new one) with python script?, I can add new strokes by:

str = fr.strokes.new()

where fr is a grease pencil frame object. But each time I do so, Blender will create a new grease pencil color palette with pink color. I want to ask how to set the color palette of the created stroke. Thanks.

PS: The document [1] of bpy.types.GPencilStrokes.new(colorname="") shows that the new method has a colorname parameter (which may be relevant), but I still do not know to set it.

PS: Blender version 2.78c

[1] https://docs.blender.org/api/current/bpy.types.GPencilStrokes.html?highlight=stroke#bpy.types.GPencilStrokes.new


1 Answer 1


A grease pencil object has a list of palettes, each palette has a list of colours. The name of each colour can be used in strokes.new() or be set after creation.

So you can use str = fr.strokes.new(colorname='red') or

str = fr.strokes.new()

An example script that creates a palette and colours -

import bpy

scn = bpy.context.scene

if scn.grease_pencil:
    gp = scn.grease_pencil
    gp = bpy.data.grease_pencil.new('mygp')
    scn.grease_pencil = gp

if gp.layers:
    gpl = gp.layers.active
    gpl = gp.layers.new('gpl', set_active = True )

if gpl.frames:
    fr = gpl.active_frame
    fr = gpl.frames.new(1)

if gp.palettes:
    gp_palette = gp.palettes.active
    gp_palette = gp.palettes.new('mypalette')

if 'red' in gp_palette.colors:
    red_col = gp_palette.colors['red']
    red_col = gp_palette.colors.new()
    red_col.name = 'red'
    red_col.color = (1.0,0.0,0.0)

if 'blue' in gp_palette.colors:
    blue_col = gp_palette.colors['blue']
    blue_col = gp_palette.colors.new()
    blue_col.name = 'blue'
    blue_col.color = (0.0,0.0,1.0)

str = fr.strokes.new(colorname=red_col.name)
str.draw_mode = '3DSPACE'
str.line_width = 3
str.points[0].co = (2.0,1.0,0.0)
str.points[1].co = (-2.0,1.0,0.0)

str = fr.strokes.new()
str.draw_mode = '3DSPACE'
str.line_width = 3
str.points[0].co = (2.0,2.0,0.0)
str.points[1].co = (-2.0,2.0,0.0)
  • $\begingroup$ I appreciate this post a lot. The new grease pencil in late 2.7x blender is great for artists, but really sucks bad for scripting. $\endgroup$
    – patmo141
    Nov 19, 2017 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .