How to add my script python to Pose Mode menu?

Hi
Could somebody write part of script which add my script to menu? I mean I want my script here:


Here is my code, it serves to mirror the animation:

bl_info = {
    "name": "Mirror animation",
    "author": "Gal anonim",
    "version": (1,0),
    "blender": (2, 6, 6),
    "location": "???",
    "description": "Mirror animation",
    "warning": "",
    "wiki_url": "none",
    "tracker_url": "none",
    "category": "UV"}






####################################################
import bpy


start_frame=0
end_frame=18


class AnimationMirror(bpy.types.Operator):
    ''''''
    bl_idname = "animation_mirror"
    bl_label = "Mirror animation"
    bl_description = "Mirror animation - select all the bones"
    bl_options = {'REGISTER', 'UNDO'}


    def set_frame(sf):
        bpy.context.scene.frame_set(frame=sf)
        bpy.context.active_object.update(scene=bpy.context.scene)
        bpy.context.scene.update()
	
    ## execute
    def execute(self, context):
        #print("------START------")


        each_frame=start_frame
        while each_frame<=end_frame:
            set_frame(sf=each_frame)
            bpy.ops.pose.copy()
            set_frame(sf=each_frame+(end_frame-start_frame))
            bpy.ops.pose.paste(flipped=True)
            print('copying '+str(each_frame)+' to '+str(bpy.context.scene.frame_current))
            bpy.ops.anim.keyframe_insert()
            if each_frame==end_frame:
                break
            set_frame(sf=each_frame)
            bpy.ops.screen.keyframe_jump(next=True)
            each_frame=bpy.context.scene.frame_current    
	
        #print("-------END-------")
        return {'FINISHED'}






#################################################
#### REGISTER ###################################
#################################################


def add_to_menu(self, context) :
    self.layout.operator("mirror animation")
    self.layout.operator("mirror animation")
    
def register():
    bpy.utils.register_module(__name__)
    bpy.types.????.append(add_to_menu)  #based on some example I suppose that instead of ??? I need some id of pose menu


def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.?????.remove(add_to_menu)
    
if __name__ == "__main__":
    register()

If additionally somebody know how to make variable ‘start_frame’ and ‘end_frame’ as dynamically changes in blender API then I would be grateful for help. However the most important for me is how to add this script to menu.

Hi,

there are several things that don’t work here.

  1. idname of an operator has be of the form <something>.<something>. In your case e.g. “animation.mirror”

  2. in add_to_menu: The parameter of self.layout.operator is the idname of your operator. In your case

self.layout.operator("animation.mirror")
  1. You are kind of right about your “???”. You have to add you operator to “VIEW3D_HT_header” that is the header/footer of the 3d-View… so it’s
bpy.types.VIEW3D_HT_header.append(add_to_menu)
  1. you only wanna draw it when you are in pose mode. This can be handled by “add_to_menu” like that:
def add_to_menu(self, context) :     
if(context.mode == 'POSE'):self.layout.operator("animation.mirror")

i hope that helps.

best wishes

oliver

Thanks, but unfortunately it doesn’t work, there is none my script. When I enable my script in addons, then I receive many messages about missiong operator “animation.mirror”. I suppose that I will have to do mirror manually:/

can you post the new version of your script please?

correct the bl_idname:
bl_idname = “animation_mirror”

It needs to be

bl_idname = "animation.mirror"

Although the naming convention is “anim”, not “animation”