# How to add a button to outliner header via python script?

Is it possible to add a button via python to here?

The header of the outliner panel can be accessed through bpy.types.OUTLINER_HT_header. It is possible to add additional buttons to the header by appending or prepending a draw function which assigns the relevant operators to the layout. The draw function could look like the following, if your operator class is called EXAMPLE_OT_something.

def draw(self, context):
self.layout.operator(EXAMPLE_OT_something.bl_idname)


If the operator has been registered the draw function can be appended to the header. This places the button at the end of the header. Using .prepend would place it at the beginning.

bpy.types.OUTLINER_HT_header.append(draw)


Below is an example add-on that demonstrates the concept.

bl_info = {
"author": "Robert Guetzkow",
"version": (1, 0, 0),
"blender": (2, 81, 0),
"location": "Outliner",
"wiki_url": "",
"category": "Outliner"}

import bpy

class EXAMPLE_OT_something(bpy.types.Operator):
bl_idname = "example.something"
bl_label = "Do something"
bl_description = "This operator does something"
bl_options = {"REGISTER"}

def execute(self, context):
print("Hello")
return {"FINISHED"}

def draw(self, context):
self.layout.operator(EXAMPLE_OT_something.bl_idname)

classes = (EXAMPLE_OT_something,)

def register():
for cls in classes:
bpy.utils.register_class(cls)

def unregister():

for cls in classes:
bpy.utils.unregister_class(cls)

if __name__ == "__main__":
register()

• Changing the order of entries requires more work though. It's not impossible but an add-on should probably avoid that (see this old answer) – Robert Gützkow Sep 28 '20 at 21:55