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$
3
+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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks PietersonFindus! $\endgroup$ – Animik Aug 2 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.