The ID of the tool icons correspond to the names of the files in which they are stored and they can be obtained simply by looking in the appropriate Blender folder. However, icon IDs can also be obtained through the Blender Python API with the help ot the ToolSelectPanelHelper class.
Let’s import it first
1 |
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper |
Now we can get a pointer to all the tool classes in the area we need. For example, for a 3D viewport area tools:
1 |
cls = ToolSelectPanelHelper._tool_class_from_space_type('VIEW_3D') |
Now we can get the tool pointer by context.
1 |
item_group = cls.tools_from_context(bpy.context): |
If the tool is not in a tool group, we can simply get its name and icon ID:
1 |
print(item_group.label, item_group.icon) |
If a tool combines multiple tools – was registered in the API with the group=True option, we will get a pointer to a tuple, each element of which is a separate tool.
We can get their names and icon IDs by looping through the tuple elements:
1 2 |
for sub_item in item_group: print(sub_item.label, sub_item.icon) |
Full code that will display the name and ID of the icon for all tools in the 3D viewport area:
1 2 3 4 5 6 7 8 9 10 11 12 |
import bpy from bl_ui.space_toolsystem_common import ToolSelectPanelHelper cls = ToolSelectPanelHelper._tool_class_from_space_type('VIEW_3D') for item_group in cls.tools_from_context(bpy.context): if type(item_group) is tuple: for sub_item in item_group: print(sub_item.label, sub_item.icon) else: if item_group is not None: print(item_group.label, item_group.icon) |