2
$\begingroup$

How can the grease pencil brush be changed from the API? The default is Pencil, but in my addon I would like to use the Pen. I cannot find this anywhere in the documentation.

# Define grease pencil parameters
gp_mat = bpy.data.materials.new("my_mat")
bpy.data.materials.create_gpencil_data(gp_mat)
gp_mat.grease_pencil.color = [0,1,0,1]
bpy.context.scene.tool_settings.gpencil_stroke_placement_view3d = 'SURFACE'
bpy.data.brushes["Pen"].size = 5

# Add grease pencil to scene
bpy.ops.object.gpencil_add(type='EMPTY')
bpy.ops.object.mode_set(mode='PAINT_GPENCIL')
gp_obj = bpy.data.objects['GPencil']
gp_obj.data.materials.append(gp_mat)
gp_obj.active_material = gp_mat

# Change brush to pen
_________________________________________  # What goes here?
$\endgroup$

1 Answer 1

4
+50
$\begingroup$

You can change the active brush via the context tool settings like you set the gpencil_stroke_placement_view3d in your code:

bpy.context.scene.tool_settings.gpencil_paint.brush = bpy.data.brushes["Pen"]

Of course you have to use the respective name of your desired brush.

$\endgroup$
1
  • $\begingroup$ Thanks PietersonFindus! $\endgroup$
    – Animik
    Aug 2, 2020 at 17:21

You must log in to answer this question.

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