12

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?

gandalf3
  • 157,169
  • 58
  • 601
  • 1,133

1 Answers1

21

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
    addon_prefs = user_prefs.addons[__package__].preferences

    layout = self.layout
    layout.prop(addon_prefs, "use_play")
    layout.prop(addon_prefs, "use_end")


# Registration

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

# Unregistration

def unregister():
    bpy.types.RENDER_PT_render.remove(render_panel)
Fweeb
  • 7,202
  • 2
  • 32
  • 37
  • 2
    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. – JakeD Nov 16 '16 at 03: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. – Fweeb Nov 16 '16 at 12:36
  • 2
    Note: Edit Source is available by enabling "Developer Extras" in the preferences menu (Preferences > Interface ). – Zollie Feb 13 '20 at 18:52