Adding buttons to Blender areas header

With the Python API we can customize Blender interface as we need. For example, we can place the most frequently used operators to the header (top menu) of any workspace area. This way we can assemble our own ribbon with “quick favorite” buttons.

The header of each area in Blender is described in the API by its own type. For example, the 3D Viewport header is described in bpy.types.VIEW3D_HT_header.

The easiest way to determine the header type for the desired area is to click on any button on it with the right mouse button, select “Edit Source” in the drop-down menu (“Developer Extras” must be enabled in the preferences) and follow the code that opens in the Text Editor up to the class definition.

For the main Blender areas, the header types are:

3D Viewport – VIEW3D_HT_header
Image Editor – IMAGE_HT_header
UV Editor – IMAGE_HT_header
Compositor – NODE_HT_header
Texture Node Editor – NODE_HT_header
Geometry Node Editor – NODE_HT_header
Shader Editor – NODE_HT_header
Video Squiencer – SEQUENCER_HT_header
Movie Clip Editor – CLIP_HT_header
Dope Sheet – DOPESHEET_HT_header
Time Line – DOPESHEET_HT_header
Graph Editor – GRAPH_HT_header
Drivers – GRAPH_HT_header
Nonlinear Animation – NLA_HT_header
Text Editor – TEXT_HT_header
Python Console – CONSOLE_HT_header
Info – INFO_HT_header
Outliner – OUTLINER_HT_header
Properties – PROPERTIES_HT_header
File Browser – FILEBROWSER_HT_header
Asset Browser – FILEBROWSER_HT_header
Spreadsheet – SPREADSHEET_HT_header
Preferences – USERPREF_HT_header
To add any interface elements to the header, we need to define a function for drawing them, similar to the “draw” function for custom UI panels.
For example, the button for the operator adding the default cube “bpy.ops.mesh.primitive_cube_add” must be defined with the function as follws:

Not to loose the function if the scene is reloaded, we wrapped it in the @persistent decorator.

Now, to place this operator button in the 3D viewport header, let’s add our function to the header with the “prepend” method.

When using “prepend”, all interface elements defined in our function will be drawn in the header before its own buttons. We can also use the “append” method, in which case all elements from our function will be placed in the header after its own buttons.

To remove our button from the area header, we need to remove our function from the header type by calling its “remove” method:

5 2 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments