zeffii / BlenderPythonRecipes

curated snippets for bpy (mostly for Blender <= 2.79 ), some changes are needed to maintain compatibility with 2.8+
GNU General Public License v2.0
121 stars 9 forks source link

x_templates can be written much much simpler.. #3

Closed zeffii closed 8 years ago

zeffii commented 8 years ago

import bpy

class TEXT_MT_templates_my_py(bpy.types.Menu):
    bl_label = "My Python"
    bl_idname = "OBJECT_MT_custom_py_menu"

    def draw(self, context):
        self.path_menu(
            bpy.utils.script_paths("templates_my_py"),
            "text.open",
            {"internal": True},
        )

def draw_item(self, context):
    layout = self.layout
    layout.menu(TEXT_MT_templates_my_py.bl_idname)

def register():
    bpy.utils.register_module(__name__)
    bpy.types.TEXT_MT_templates.append(draw_item)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.TEXT_MT_templates.remove(draw_item)

if __name__ == "__main__":
    register()
zeffii commented 8 years ago

image

zeffii commented 8 years ago

done