I'm working on a popup menu to accelerate lip syncing within Blender Grease Pencil. I have a popup menu with a selection of all of the lip sync sounds an animator needs (ex. of mouth selection options - Menu Option 1: Silent,M,B; Menu Option 2: S,T,Ch; Menu Option 3: E; etc.).
I've created several images and keyframed them using the TimeOffset Modifier. The action I want is when you click one of the popup menu options, the TimeOffset changes its frame based on the selection you've chosen and then a keyframe is inserted. I have the selection process working, but not the keyframing part.
Here is the code for those two actions for one of the menu's selections. I would need to duplicate these lines for every offset frame and change the offset at the end of the first line. The first line works, but I can't get the second one to insert a keyframe after the first action occurs. Thanks for any help you can provide!
bpy.context.object.grease_pencil_modifiers["TimeOffset"].offset = 1
bpy.context.object.grease_pencil_modifiers["TimeOffset"].offset.keyframe_insert("frame",frame=bpy.context.scene.frame_current)
EDIT: Thanks to Chris' response below, I was able to get it to work with the following code. "Offset = 2" refers to the frame in the TimeOffset modifer:
offset_mod = bpy.data.objects["GPencil"].grease_pencil_modifiers["TimeOffset"]
offset_mod.offset = 2
offset_mod.keyframe_insert(data_path="offset", frame = current_frame)