Creating Custom UI Panels in Blender

When writing add-ons for Blender, it is important to place UI elements – buttons, fields, switches, etc., so that the user can easily find them and have convenient access to them. Blender provides to add-on developers the following areas to place their custom UI:

  1. The “Sidebar” on the left side of any Blender work area. Also named as the “N-panel” since it is most often opened by pressing the “n” key on the keyboard.
  2. Panels in the Properties work area.

To create a panel with UI for our add-on, we need to define a panel class, inheriting from the “bpy.types.Panel” system class and register it in the Blender API.

The simplest custom panel class has the following structure:

The location of the panel is determined by the parameters ​​that are specified at the beginning of the class definition:

bl_space_type – indicates the general location of the panel – the area in which it needs to be placed. For example:

VIEW_3D – 3D Viewport area
IMAGE_EDITOR – UV/Image Editor area
NODE_EDITOR – Node Editor area
SEQUENCE_EDITOR – Video Sequencer area
CLIP_EDITOR – Movie Clip Editor area
DOPESHEET_EDITOR – Dope Sheet area
GRAPH_EDITOR – Graph Editor area
NLA_EDITOR – Nonlinear Animation area
TEXT_EDITOR – Text Editor area
PROPERTIES – Properties area
FILE_BROWSER – File Browser area
SPREADSHEET – Spreadsheet area

bl_region_type – Specifies the region where the panel will be placed within the workspace.
To place the created panel on the area Sidebar, we need to specify the “UI” value for this parameter.
Other possible values: WINDOW, HEADER, CHANNELS, TEMPORARY, TOOLS, TOOL_PROPS, PREVIEW, HUD, NAVIGATION_BAR, EXECUTE, FOOTER, TOOL_HEADER, XR.

bl_category – defines the group in which the panel with the UI will be placed. If an already existing group is specified, the panel will be appended to it. If any new name is specified, such a group will be created and the panel placed in it.

bl_label – The last parameter simply specifies the title of the UI panel being created.

For example, in order to place our panel in the 3D viewport area, in its Sidebar, in the Tools group – we need to specify:

If we specify some unique value instead of “Tool”, a tab with the same name will be created in the area Sidebar and our UI panel will be placed on it.

An example of a class for placing a UI panel in the Sidebar of the 3D viewport workspace:

To place our panel on any tab of the Properties work area, instead of the bl_category parameter, the bl_context parameter is used.

bl_context – possible values ​​corresponding to Properties area tabs: render, output, view_layer, scene, world, collection, object, modifier, physics, constraint, data, material, texture.

For example, in order to place our panel in the Properties area, on the Render tab, we need to set:

A sample class for placing a UI panel in the Properties area on the Render tab:

For Blender 2.79 and oldest versions, please see this tutorial

3.7 3 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments