Is it possible to add a button to an existing panel or node with python?

Is it possible to add a new button to an existing panel or an existing node that runs a custom operator?

How can I do this?

Yes. You need to find the class that defines that panel (usually pretty easy to do by right-clicking a button or setting in the panel and choosing Edit Source). From there, you just need to define a function and append it to that class. As an example, I do this in my Render Music add-on (in __init__.py, starting at line 82). Below is the relevant example that adds two checkboxes (properties defined by the add-on) to the Render Panel (RENDER_PT_render):

def render_panel(self, context):
user_prefs = context.user_preferences

layout = self.layout

# Registration

def register():
bpy.types.RENDER_PT_render.append(render_panel)

# Unregistration

def unregister():
bpy.types.RENDER_PT_render.remove(render_panel)

• You explain how to add a panel to another, but not how to remove in the unregister method. I believe it is by using remove instead of append. Nov 16 '16 at 3:27
• Yes. That is correct. I left it off in the reply because I didn't want to confuse the issue too much. The unregister function is in the full source that's linked, though. Nov 16 '16 at 12:36
• Note: Edit Source is available by enabling "Developer Extras" in the preferences menu (Preferences > Interface ). Feb 13 '20 at 18:52