I can append my custom item to a menu. It either place it last or first (append - prepend). bpy.types.VIEW3D_MT_add.append(menu_func)
It works and it does the job, but is not exactly a dream.
But say for example I want to append an item to a specific index. Say for example after the “Join” entry.
I would do something like this in python.
a = [1,3,4]
a.insert(a.index(3), 2)
Not sure how to use the API though in an advanced way. There are “items()” or “keys()” or accessing the RNA properties as such. bpy.types.VIEW3D_MT_object...
You should create a function that that modifies menu. It makes sense as several add-ons can modify one menu. In this function you have access to self.layout and you can do anything you want with it.
I’m sorry, but I’m not understanding how to insert a menu command at a specific index (per the original post) with self.layout from the doc link you sent. My other research shows people overriding the menus’ draw functions with a lot of code.
You aren’t appending menu items, you’re appending function pointers. So, while you are seeing 30 lines in a menu, it is likely a single function drawing them all. Short of rewriting the menu with your item where you want it to be, it isn’t possible.
yep, You can append and prepend easily, index is not available.
You can try doing things like: copy original source of class bpy.types.TOPBAR_MT_file, edit its draw function and re-register, or catch and filter draw function calls, but it is uphill battle.