Grease Pencil Edit Mode?

Ummm. OK. Would someone explain this to me. I’m trying to change mode to edit strokes, bpy.ops.object.mode_set(mode=‘GPENCIL_EDIT’). It tells me GPENCIL_EDIT is not an option and I’m looking right at it. How do I change to GPENCIL_EDIT using python.

What is the error exactly? Does an object exist or just the grease pencil strokes?

best thing I can tell ya is create a grease pencil stroke on object and run the code. It says that GPENCIL_ EDIT isn’t an option for mode set ,but yet you can toggle to it. Grease pencil stroke is set to object and surface if that matters.

Here’s screenshots, makes no sense.

Blender Screenshot


Try running it from an operator like this:

import bpy

def main(context):

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

Spacebar search for Simple operator.

Running it the way you did puts it’s context in the text editor.

I’ll try that and see what happens. I found another way to enter edit mode.['GPencil'].use_stroke_edit_mode = True

I think that would be the better way, I just thought you wanted to use the ops way. That non-ops is better as it won’t depend on context.

The edit mode for Grease Pencil is a bit of a hack, since you can’t actually set that particular mode value on any particular object and expect it to keep working when you select another object.

As AFWS #6 mentions, the only really reliable way is to use['GPencil'].use_stroke_edit_mode = True