Showing custom UI panel in Blender by pressing keycodes

When creating add-ons for Blender, developers almost always create the user UI panel with tools that provide the main functionality of the add-on. Typically, such custom panels are placed in the N-panel block, called by pressing the N key. However, if it is assumed that the user will often call the panel with add-on tools, its call can be bound to a keyboard shortcut and the panel can be called from the keyboard.

For example, let’s create a simple custom panel with two buttons, to which we will bind a call to the basic operators of adding a cube and Suzanne to the scene.

Register our panel class in the Blender Python API:

Now the N-panel has a tab with the name of our custom panel – “TEST”. By clicking on it, we can open the panel and click on the operator buttons to add meshes to the scene.

In order to call this panel by pressing certain keys on the keyboard, first we need to get a pointer to the keymap:

Now we can create a new keymap element in which we initiate execution of the “wm.call_panel” operator. In this command, we also set the key combination for calling the operator – in our example, let it be the combination of Shift + T keys:

Set for this keymap element the “bl_idname” of our panel that will be called:

And additionally, turn off the “keep_open” parameter so that the panel closes immediately after pressing the buttons on it.

Now, when we press the Shift + T key combination, our panel will be opened in a separate pop-up window.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments