Custom Icons for EnumProperty in Blender

We can use custom icons, icons loaded from external files, and not embedded in Blender libraries, for example, to add customization to operator call buttons in UI panels. However, it is not only buttons that may require custom icons. Using the Blender Python API, we can add customization to drop-down list items or switches that are created based on the EnumProperty type.

First, let’s create a class for the custom panel, on which we will later place a group switch and a drop-down list.

Don’t forget to register it in the Blender Python API, so that our custom panel will be displayed in the 3D viewport area, in the N-panel.

In the draw() function, we will further define the displaying of our UI elements.

But first, let’s create a list for custom icons and load several icons from external files into it.

Our “icons” list is created using the “previews” module from the bpy.utils package.

The new() method is used to initialize the list.

Next, let’s load three icons from external files into it. We will load each icon using the load() method, specifying the full path to its file.

Now, in order to create a switch and a drop-down list, we will use the “EnumProperty” to create the “test_enum” object containing three elements in the “items” tuple.

Each element (a separate line in the “items” parameter) is an ordered tuple of properties. In the fourth place, we specify a link to the corresponding icon from the list we created earlier. This way we bind the icons to the list elements.

All that remains for us to do, is to register the displaying of the “test_enum” object in the draw() function of our user panel.

To make it look like a group switch, the “expand” parameter must be set to True.

The “col” wrapper is necessary to locate radio-buttons vertically, one under the other.

And, after the separator, place the same object in the form of a drop-down list:

Running the code, we will see that each radio button and drop-down list item now has its own icon loaded from an external file.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments