script Custom 3d menu to import a scene

How can I make a custom menu to append a whole scene?

I have got a need to add a custom menu.I got how to make it for a custom object, but I can’t understand how to add a custom menu to imjport in bender a whole scene that includes mesh, bones, controllers, layers etc etc

For example I want that when I press shift a together with armature bones I have my custom button to import my whole scene that is my rig. Just a way to make it less boring than opening the file everytime and run the scripts for sliders controllers that I made manually anytime.

Thank you.

Ok I found something and tried to modify it to fit my needs.
I tried to change it to get it in the Shift_A add menu so I could append my scene from there but it fails.Any advice?

bl_info = {“name”: “yellowsubmarine”,
“author”: “anonb”,
“version”: (1, 0, 0),
“blender”: (2, 72, 0),
“location”: “Add > Mesh”,
“description”: “Create yellowsubmarine primitive.”,
“warning”: “”,
“wiki_url”: “”,
“tracker_url”: “”,
“category”: “Add Mesh”}

if “bpy” in locals():
import imp

import bpy
import bmesh
import math
from mathutils import *

class OBJECT_OT_addSubmarine(bpy.types.Operator):
‘’’
Class representing an operator for adding a yellow submarine
‘’’
bl_idname = “addSubmarineButton” #name used to refer to this operator
bl_label = “Add Submarine” #operator’s label
bl_options = {‘REGISTER’, ‘UNDO’}
bl_description = “Add a yellow submarine” #tooltip

def execute(self, context):
    '''
    Function to process a click on the "Add Submarine" button
    '''
    bpy.ops.wm.link_append(directory="C:\\Users\\Yourname\\Desktop\	est_append\\yellowsubmarine.blend\\Scene\\", 
        filename="Submarine", link=False) #append submarine from .blend file
    return{'FINISHED'}

def menu_item(self, context):
self.layout.operator(yellowsubmarine.bl_idname, text=“yellowsubmarine”, icon=“PLUGIN”)

def register():
bpy.utils.register_module(name)
bpy.types.INFO_MT_mesh_add.append(menu_item)

def unregister():
bpy.utils.unregister_module(name)
bpy.types.INFO_MT_mesh_add.remove(menu_item)

if name == “main”:
register()

last changes thanks to Jerryno. Still I can’t get my menu item, I get no error when I install the script or trty to run it.

bl_info = {“name”: “yellowsubmarine”,
“author”: “anonb”,
“version”: (1, 0, 0),
“blender”: (2, 65, 0),
“location”: “Add > Mesh”,
“description”: “Create yellowsubmarine primitive.”,
“warning”: “”,
“wiki_url”: “”,
“tracker_url”: “”,
“category”: “Add Mesh”}

if “bpy” in locals():
import imp

import bpy
import bmesh
import math
from mathutils import *

class OBJECT_OT_addSubmarine(bpy.types.Operator):
‘’’
Class representing an operator for adding a yellow submarine
‘’’
bl_idname = “addSubmarineButton” #name used to refer to this operator
bl_label = “Add Submarine” #operator’s label
bl_options = {‘REGISTER’, ‘UNDO’}
bl_description = “Add a yellow submarine” #tooltip

def execute(self, context):
    '''
    Function to process a click on the "Add Submarine" button
    '''
    bpy.ops.wm.link_append(directory="C:/Users/Youruser/Desktop/test_append/yellowsubmarine.blend/Scene/", 
        filename="Scene", link=False) #append submarine from .blend file
    return{'FINISHED'}

def menu_func(self, context):
self.layout.operator(“addSubmarineButton”)

def register():

bpy.utils.register_module(name)

this adds your menu to shift-a add menu

bpy.types.INFO_MT_add.prepend(menu_func)

def unregister():
# bpy.utils.unregister_module(name)
bpy.types.INFO_MT_add.remove(menu_func)

if name == “main”:
register()

The script is half working now. I can get the nenu to add it, but I couldn’t figure out how to fix the error shown in the picture.Any idea?

Here is the last version of the code I used.

bl_info = {“name”: “yellowsubmarine”,
“author”: “anonb”,
“version”: (1, 0, 0),
“blender”: (2, 72, 0),
“location”: “Add > Mesh”,
“description”: “Create yellowsubmarine primitive.”,
“warning”: “”,
“wiki_url”: “”,
“tracker_url”: “”,
“category”: “Add Mesh”}

if “bpy” in locals():
import imp

import bpy
import bmesh
import math
from mathutils import *

class OBJECT_OT_addSubmarine(bpy.types.Operator):
‘’’
Class representing an operator for adding a yellow submarine
‘’’
bl_idname = “mesh.addsubmarine” #name used to refer to this operator
bl_label = “Add Submarine” #operator’s label
bl_options = {‘REGISTER’, ‘UNDO’}
bl_description = “Add a yellow submarine” #tooltip

def execute(self, context):
    '''
    Function to process a click on the "Add Submarine" button
    '''
    bpy.ops.wm.link_append(directory="C:/Users/Youruser/Desktop/test_append/yellowsubmarine.blend/Scene/", 
        filename="Scene", link=False) #append submarine from .blend file
    return{'FINISHED'}

def menu_item(self, context):
self.layout.operator(OBJECT_OT_addSubmarine.bl_idname, text=“yellowsubmarine”, icon=“PLUGIN”)

def register():
bpy.utils.register_module(name)
bpy.types.INFO_MT_mesh_add.append(menu_item)

def unregister():
bpy.utils.unregister_module(name)
bpy.types.INFO_MT_mesh_add.remove(menu_item)

if name == “main”:
register()

Attachments


bpy.ops.wm.link_append is wrong function name? In 2.72 it appears to be either bpy.ops.wm.link() or bpy.ops.wm.append().

Perfect!!! one thousand million thanks, kesonmis It was that it seems it’s working now.This can be very helpful to give out custom rigs made with blender so they can just import it .Later I am going to publish also the code that I made for sliders.

bl_info = {“name”: “yellowsubmarine”,
“author”: “anonb”,
“version”: (1, 0, 0),
“blender”: (2, 72, 0),
“location”: “Add > Mesh”,
“description”: “Create yellowsubmarine primitive.”,
“warning”: “”,
“wiki_url”: “”,
“tracker_url”: “”,
“category”: “Add Mesh”}

if “bpy” in locals():
import imp

import bpy
import bmesh
import math
from mathutils import *

class OBJECT_OT_addSubmarine(bpy.types.Operator):
‘’’
Class representing an operator for adding a yellow submarine
‘’’
bl_idname = “mesh.addsubmarine” #name used to refer to this operator
bl_label = “Add Submarine” #operator’s label
bl_options = {‘REGISTER’, ‘UNDO’}
bl_description = “Add a yellow submarine” #tooltip

def execute(self, context):
    '''
    Function to process a click on the "Add Submarine" button
    '''
    bpy.ops.wm.append(directory="C:/Users/Youruser/Desktop/test_append/yellowsubmarine.blend/Scene/", 
        filename="submarine", link=False) #append submarine from .blend file
    return{'FINISHED'}

def menu_item(self, context):
self.layout.operator(OBJECT_OT_addSubmarine.bl_idname, text=“yellowsubmarine”, icon=“PLUGIN”)

def register():
bpy.utils.register_module(name)
bpy.types.INFO_MT_mesh_add.append(menu_item)

def unregister():
bpy.utils.unregister_module(name)
bpy.types.INFO_MT_mesh_add.remove(menu_item)

if name == “main”:
register()

Just make your own scene name it change now the name in the path and the name of the scene and it’s working I leave also the link to the scene that I used for testing this script.http://blenderpython.orgfree.com/Scripts/yellowsubmarine.blend

Which is where I took the idea to make such script: read here