Hello I am creating an addon for blender. I have rigged a character, with controller handlers, sliders to control the rig, etc.

I need now to understand how to create a custom 3D menu to append the whole scene in my viewport, just a way to make it less boring than appending it everytime.

I learned how to add a custom object, but I am encountering difficulty in making a custom menu to append an entire scene.

To be clear I want to add a custom button under the bone and armature section when you hit ⇧ ShiftA to append in the 3D scene.

• Welcome to the site :) I've attempted to make your question clearer by editing it. If I've mis-interpreted anything or you disagree with my edits, feel free to roll them back at any time.
– gandalf3
Dec 7 '14 at 19:56
• Thanks yes you interprerted it right. I need that when I hit that shortcut I could append my rig from the blend file that I'd install somewhere in blender folders. It would be good if it's esier also a button in 3d toolshelf to do the append. I just can't get it working. I'll post you some code. Dec 7 '14 at 20:38
• here the code www.pastebin.com/N1kdQW9z Dec 7 '14 at 20:38

Blender 2.8x

def menu_func(self, context):
# bl_idname should be in form of "something.something"
# or YourClass.bl_idname

def register():
# register classes so blender knows about them
bpy.utils.register_class(MyOperatorClass)
# other menu classes you can find in \scripts\startup\bl_ui\
# by looking into the files there (i.e.: space_view3d.py)

def unregister():
bpy.utils.unregister_class(MyOperatorClass)

if __name__ == "__main__":
register()


Blender 2.7x

def menu_func(self, context):
# bl_idname should be in form of "something.something"
# or YourClass.bl_idname

def register():
# register classes so blender knows about them
bpy.utils.register_module(__name__)
# other menu classes you can find in \scripts\startup\bl_ui\
# by looking into the files there (i.e.: space_view3d.py)

def unregister():
bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()

• thanks Jerryno. I did the changes that you showed me, but still I get no option in the menu even if there is no error when I install the script or try to run it. Here comes the new pastebin pastebin.com/XWgAWNBn Dec 7 '14 at 21:25
• In your script the register_module and unregister_module should not be commented, they throw error when they have nothing to register so thats why i commented them. I edited the answer to be more detailed Dec 8 '14 at 7:21

There are some small picky details you need to get right for your script to work.

Your class bl_idname should be

bl_idname = "mesh.addsubmarine"


Notice the mesh. prefix and the all lowercase in the name. This also needs to be copied to the name used in menu_func. You could use OBJECT_OT_addSubmarine.bl_idname in menu_func so that it always matches your class setting.

In register and unregister you need to register/unregister your operator class. Either with bpy.utils.register_class(OBJECT_OT_addSubmarine) or bpy.utils.register_module(__name__). Jerryno may have confused you as he was highlighting the lines you need to add for the menu entry.

The use of bpy.types.INFO_MT_add is incorrect. This refers to the top menu which contains categories like mesh curve etc. You want to use

bpy.types.INFO_MT_mesh_add.append(menu_func)

• You can edit other's people answers to not have multiple same answers you know. Dec 8 '14 at 7:24
• @Jerryno See meta.blender.stackexchange.com/q/429/599. If someone takes the time to write out a detailed explanation of an answer, even if it's using the same code/method as another answer, I'd say they deserve to have their own answer and rewards (or downvotes) that come with it. We like good answers here, and correctness is only half of what makes a good answer; it has to be communicated well too (multiple explanations are better than 1). Aside from that, we are trying to boost our answer ratio. Multiple answers are not a bad thing, and I don't see any reason to try and suppress them.
– gandalf3
Dec 8 '14 at 8:03

Thanks, guys.I had to register again hence I lost my mail_password. so I can add the answer for now rather than comment. I have been testing the changes that sambler proposed.Now I get an error in the console

Traceback >Most recent call last>: File "testsubmarine4.py", line54, in File "testsubmarine4.py",line47, in register Name Errror:mame menu_func is not defined

Here is the code I used http://pastebin.com/5izAYFwH

I also tried using bpy.utils.register_class(OBJECT_OT_addSubmarine) to register unregister but I get the same error in console.

Thanks Chris.I fixed that.I put menu item also in register. now I just get one in the console that is

self.layout.operator(mesh.addsubmarine.bl_idname, text="yellowsubmarine", icon="PLUGIN")

• Looking at your code, it looks like you forgot to change menu_func to menu_item in the register method. Dec 8 '14 at 20:21
• On line 43 you want OBJECT_OT_addSubmarine.bl_idname not mesh.addsubmarine.bl_idname Dec 9 '14 at 6:23