Running py scripts from custom menu

I have a bunch of separate .py scripts that I’ve created, and I want to create a menu so I can run them easily.

I thought this should be pretty easy to do, but I can’t find much info on it. So far I’ve got this which shows what I want to do but obviously does not work:

import bpy

class CustomMenu(bpy.types.Menu):
    bl_label = "My Scripts"
    bl_idname = "OBJECT_MT_custom_menu"

    def draw(self, context):
        layout = self.layout
        filename1 = "D:\My Scripts\"
        filename2 = "D:\My Scripts\"
        menuTest1 = exec(compile(open(filename1).read(), filename1, 'exec'))
        menuTest2 = exec(compile(open(filename2).read(), filename2, 'exec'))
        layout.operator(menuTest1, text="Test 1")
        layout.operator(menuTest2, text="Test 2")

def draw_item(self, context):
    layout = self.layout

def register():

def unregister():


if __name__ == "__main__":

It just shows an empty menu. Basically I want to use exec as a menu command to run external scripts. Perhaps this is not the right approach though??

are you getting any errors in the console? I would think you’d be getting a lot of errors since you’re trying to jam compiled code as an argument into layout.operator()

actually looking even closer at your code I’m not even sure what you’re hoping to do- exec doesn’t return anything? So you’re effectively passing None into layout.operator

I know this code doesn’t work at all but I have no idea how to do it correctly…
I’m just trying to create a menu item that runs exec, which runs the scripts

This seemed like a pretty nice functionality to have so I googled around to see if someone else had a similar idea and already created something for it. At first glance this seems to offer everything you need:

It was last updated in November so I don’t know if it works with the very latest version of Blender but only one way to find out. :wink:

Wow that does sound exactly what I am looking for!
Unfortunately it doesn’t seem to work with 2.93.6

Get errors when trying to add a new button :frowning: