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")
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
gp_obj = bpy.data.objects['GPencil']
gp_obj.active_material = gp_mat

# Change brush to pen
_________________________________________  # What goes here?

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.

  • $\begingroup$ Thanks PietersonFindus! $\endgroup$
    – Animik
    Aug 2 '20 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.