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):
        return {'RUNNING_MODAL'}

    def modal(self, context, event):
        if event.type == 'D' and event.value == 'PRESS':
        elif event.type == 'ESC':
            return {'CANCELLED'}
        return {'RUNNING_MODAL'} 

def draw_curve():
    bpy.context.scene.tool_settings.annotation_stroke_placement_view3d = "SURFACE"

The answer is simple: the gpencil.annotate() call on the last line needs to include the argument "INVOKE_DEFAULT".


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.