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.

  • $\begingroup$ 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. $\endgroup$ – gandalf3 Dec 7 '14 at 19:56
  • $\begingroup$ 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. $\endgroup$ – anonb Dec 7 '14 at 20:38
  • $\begingroup$ here the code www.pastebin.com/N1kdQW9z $\endgroup$ – anonb Dec 7 '14 at 20:38

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

  • $\begingroup$ You can edit other's people answers to not have multiple same answers you know. $\endgroup$ – Jaroslav Jerryno Novotny Dec 8 '14 at 7:24
  • 3
    $\begingroup$ @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. $\endgroup$ – gandalf3 Dec 8 '14 at 8:03
def menu_func(self, context):
    self.layout.operator("YOUR OPERATOR BL_IDNAME")
    # bl_idname should be in form of "something.something"
    # or YourClass.bl_idname

def register():
   # register classes so blender knows about them
   # this adds your menu to shift-a add object menu
   # if you want to add to mesh menu use INFO_MT_mesh_add
   # other menu classes you can find in \scripts\startup\bl_ui\
   # by looking into the files there (i.e.: space_view3d.py)

def unregister():

if __name__ == "__main__":
  • $\begingroup$ 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 $\endgroup$ – anonb Dec 7 '14 at 21:25
  • $\begingroup$ 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 $\endgroup$ – Jaroslav Jerryno Novotny Dec 8 '14 at 7:21

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

line 43, in menu_item NameError:

I Also tried to write it either way as was suggested:

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

If I interpret well what I had to do, but still the same error in line 43. This is the error that I get in console. here is the last code I used trying to make the changes also in line 43 http://pastebin.com/f9LSTUcd

  • $\begingroup$ Looking at your code, it looks like you forgot to change menu_func to menu_item in the register method. $\endgroup$ – Chris Dunaway Dec 8 '14 at 20:21
  • $\begingroup$ On line 43 you want OBJECT_OT_addSubmarine.bl_idname not mesh.addsubmarine.bl_idname $\endgroup$ – sambler Dec 9 '14 at 6:23
  • $\begingroup$ Thanks,Sambler, I did that change and wow.It's getting closer now finally I can see the button in the menu when I hit the shortcut to add the new scene. the problem is that it's giving me an error in line 38 that I quite don't understand.I named in the description the file to import Scene in that like cause it's named scene in the blend file scene folder. I attach the pick of the error imgur.com/9GDfzh8 $\endgroup$ – anonb Dec 9 '14 at 10:47
  • $\begingroup$ Finally it's working.Thanks to kesonmis.It seems that the iussue was with some changes with blender 2.72.As kesonmis pointed bpy.ops.wm.link_append is wrong now it's donw by bpy.ops.wm.link() or bpy.ops.wm.append() so here is the final code working for those who will need such script too. pastebin.com/vk7we7KU $\endgroup$ – anonb Dec 16 '14 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.