In my addon, I need to do a bunch of stuff while running modal. One of those things is drawing with a grease pencil, and then processing the curve. By grease pencil, I mean just the simple annotation tool. However, I am not able to get the grease pencil to draw from modal. If I call my draw_curve() function defined below from a button, it works fine. But from modal, the cursor does not become a pencil, and I cannot draw. What am I missing?
(I guess it might have something to do with detecting the left mouse press to actually commence drawing a stroke, but this worked in modal in Blender 2.7x without any further steps, and I'm having trouble figuring out what else 2.8 wants.)
Thanks in advance!
class MYADDON_OT_modal_operator(bpy.types.Operator):
bl_idname = "myaddon.modal_operator"
bl_label = "Modal Operator"
bl_options = {"REGISTER", "UNDO"}
def invoke(self, context, event):
bpy.ops.object.mode_set(mode='OBJECT')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def modal(self, context, event):
if event.type == 'D' and event.value == 'PRESS':
draw_curve()
elif event.type == 'ESC':
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def draw_curve():
bpy.context.scene.tool_settings.annotation_stroke_placement_view3d = "SURFACE"
bpy.ops.wm.tool_set_by_id(name="builtin.annotate")
bpy.ops.gpencil.annotate()