# Why can't I insert a keyframe into the prop from the operator panel?

In this code example, I try to call an operator popup, in which I put a "location" property of the active object, I'd like to right-click to insert or remove keyframes from these properties, but that doesn't seem to work. I wonder if it's a bug, or my problem, It would be really interesting to understand why, and possibly, how I can fix this?

import bpy

class MYPANEL_PT_Panel(bpy.types.Panel):

bl_label = "Test"
bl_idname = "MYPANEL_PT_Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Test"

def draw(self, context):

layout = self.layout
layout.operator("mypanelop.test", text = "Test")

class MYPANELOP_OT_Test(bpy.types.Operator):
""" """
bl_idname = "mypanelop.test"
bl_label = "Test"
bl_options = {'INTERNAL'}

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

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self,width=300)

def draw(self, context):
layout = self.layout
ob = context.object
if ob:
layout.prop(ob,'location')

classes = (MYPANEL_PT_Panel, MYPANELOP_OT_Test)

def register():

for cls in classes:
bpy.utils.register_class(cls)

def unregister():

for cls in classes:
bpy.utils.unregister_class(cls)

if __name__ == "__main__":
register()


The layout.prop that you're using is not in a Panel, but in the Operator dialog, which serves as an UI to an operation itself, and skips UI events that call for other operators (like the bound key to call 'anim.keyframe_insert', or to invoke another dialog for 'buttons.context_menu' that you mention)..

So if the function of the operator is to also insert a keyframe, you need to do that in the execution call.

import bpy

class MYPANEL_PT_Panel(bpy.types.Panel):

bl_label = "Test"
bl_idname = "MYPANEL_PT_Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Test"

def draw(self, context):

layout = self.layout
layout.operator("mypanelop.test", text = "Test")

class MYPANELOP_OT_Test(bpy.types.Operator):
""" """
bl_idname = "mypanelop.test"
bl_label = "Test"
bl_options = {'INTERNAL'}

def execute(self,context):
# INSERTING KEYFRAME
context.object.keyframe_insert(data_path='location')
return{'FINISHED'}

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self,width=300)

def draw(self, context):
layout = self.layout
ob = context.object
if ob:
layout.prop(ob,'location')

classes = (MYPANEL_PT_Panel, MYPANELOP_OT_Test)

def register():

for cls in classes:
bpy.utils.register_class(cls)

def unregister():

for cls in classes:
bpy.utils.unregister_class(cls)

if __name__ == "__main__":
register()