I’d like to add an icon button next to the copy & paste icon buttons in the F-Curve Modifier panel.
Looking at the Blender source code, the panel’s name is GRAPH_PT_modifiers. Knowing that, I am using the following code (which works for adding to menus).
If you rightclick on the button and press ‘Edit Source’ is says that the button is not from a script, it is written inside the C codebase.
However you can place the function in another useful place, such as the toolbar.
Right click and edit source again: blender\3.0\scripts\startup\bl_ui\space_graph.py:104
Good thing is that you can append your operator to an existing menu or toolbar without having to modify the source (though if you really have to modify it you still can).
Hi! Thank you for the reply! Yes, I’m familiar with editing the source from the startup\bl_ui files and appending a menu function. Could you please expand upon your last comment on how to modify the source? This is for an add-on, so I’d like for it to install a button in the user interface. It seems like one can only prepend or append to a toolbar, but not insert an operator at a specific location. Could I somehow access the panel’s layout and add a function in it? Panel.layout seems to be readonly. Thank you!
One problem is that you can’t modify these panels since they are implemented in the C source code.
If you go to the space_graph.py file you can see only that there are only menu items or the header toolbar that are extensible.
One flexible way is to append, at the last place of the top toolbar. But not in the place you want.
Another way is to modify your source code, which is a bit monolithic approach but at least you are very explicit. Adding this if statement first, will protect from breaking, just in case your addon isn’t loaded at startup or is inactive.
There is also another very advanced technique that you can modify the menus. I have not tried it yet. I am thinking if it causes any instability in the long term.
I did this a few years ago when I made an incremental save addon and wanted to insert it in-between the Save entries under File. It kinda still “just works” ™
The procedure I used was roughly:
Getting the panel’s draw method source using inspect
String search and find the entry after which to insert.
Insert my own entry.
Ran exec to compile the new draw method.
Use _dyn_ui_initialize() on the panel to get the draw functions list
Replace the old draw method with the newly compiled one (backup the old)