I want to make a pie menu for Blender's toolbar, but I don't know the name of the icon

I wrote this code to create a pie menu for the toolbar.

class my_translate_piemenu(Menu):
bl_label = "Translate"
bl_idname = "my_translate_piemenu"  
def draw(self, context):
    layout = self.layout
    pie = layout.menu_pie()
    pie.operator("wm.tool_set_by_id", text = "Annotate").name = 'builtin.annotate'
    pie.operator("wm.tool_set_by_id", text = "Rotate").name = 'builtin.rotate'
    pie.operator("wm.tool_set_by_id", text = "Transform").name = 'builtin.transform'
    pie.operator("wm.tool_set_by_id", text = "Select Box").name = 'builtin.select_box'
    pie.operator("wm.tool_set_by_id", text = "Cursor").name = 'builtin.cursor'
    pie.operator("wm.tool_set_by_id", text = "Move").name = 'builtin.move'
    pie.operator("wm.tool_set_by_id", text = "Measure").name = 'builtin.measure'
    pie.operator("wm.tool_set_by_id", text = "Scale").name = 'builtin.scale'
    pie.separator()
    pie.separator()

Here is the resulting pie menu.

I would like to add an icon to this pie menu.

To add an icon, you need to write “icon = hoge” as the third argument of “pie.operator()”.
However, I don’t know the name of the toolbar icon.
I used an add-on called “Develolpment: Icon Viewer,” but it could not tell me the name of the icon in the toolbar.

Also, I searched Google and found similar questions to mine, but it didn’t tell me what I needed to do…

Can anyone tell me how to know the name of the toolbar icon when specifying it in Python code?

Translated with DeepL Translate: The world's most accurate translator (free version)

Try to search in the source file of that particular tool. Simply right-click on the icon and then choose edit source then check for the icon name.

You need to take a look at “WM_OT_toolbar_fallback_pie” as an example.
Check “draw_fallback_tool_items_for_pie_menu” in space_toolsystem_common.py,
you will need to use “icon_value” rather than “icon” argument.

1 Like

A while ago, having that very problem, I made a cheat sheet

Cheat sheet for icons

I used it in one of my addons like this:

row.operator(
“object.bmapvis2_config”, text=“Provider”, icon=“WORLD_DATA”
).cmd = “providers”

HTH

Thank you for reply.

Right-clicking on the icon did not bring up the “Edit source” option.
a
This image shows the screen when you right-click on any icon.
I’m using Blender version 2.91.2, is it not possible to show the “Edit source”?
Or am I doing something wrong?

For a full list of icons accessible from blender use the addon included (Development: Icon Viewer)

to have the option “Edit Source”

2 Likes

Thanks for the reply.
I used “Development: Icon Viewer” to look at the icon list, but I couldn’t find the toolbar icon I wanted to use in it.
Does this mean that I can’t use the icons in the toolbar myself?

You should have all this checked in preferences/interface

1 Like

Oh so you want to use the big color icons…
maybe this could help:

1 Like

Thank you for your kind reply.

I looked at the site you gave me.
I found out that there are two types of icons in Blender and that the large size colored icons I’m trying to use are .dat files in [2.91\datafiles\icons].
But I couldn’t find anything more than that…

I tried right-clicking on the icon I want to use in the Blender toolbar and going to “Edit source” to see the code, but I’m not sure what code I need to write to use it in the pie menu.

Translated with www.DeepL.com/Translator (free version)

See the function: _icon_value_from_icon_handle(icon_name)
In the file: scripts\startup\bl_ui\bl_ui\space_toolsystem_common.py

I modified the function to print the Tool Panel icon names to the system console as follows:
ops.transform.translate
ops.transform.rotate
ops.transform.resize
ops.transform.transform
ops.gpencil.draw
ops.view3d.ruler
ops.mesh.primitive_cube_add_gizmo
ops.generic.select_box
ops.generic.cursor

Thank you very much.
I’m really sorry for the delay in replying.

I looked at the _icon_value_from_icon_handle function in space_toolsystem_common.py.
By modifying it, do you mean that I should write the code you gave me somewhere in the _icon_value_from_icon_handle function?

If so, where should I put it?

I don’t recommend modifying the code in _icon_value_from_icon_handle, my intention was to direct you to where and how I retrieved the names of the icons that you are interested in so that you might examine the script in \2.93\scripts\startup\bl_ui\space_toolsystem_common.py to see how the icons are retrieved.

Hope this helps

Space_toolsystem_common.ToolSelectPanelHelper(). _icon_value_from_icon_handle(“ops.generic.select_box”)

↑By writing it like this, I was able to successfully get the toolbar icon!
Perhaps someone else told me about this a while ago, but I didn’t understand it at the time due to my lack of understanding.

Thank you very much!

1 Like

I was able to resolve this question.
Thank you to everyone who helped me.

Sorry again when I said it was resolved.
I have one more question.

I don’t know how to check the icon_value of the icon in the toolbar.
I know “ops.generic.select_box” etc. because you wrote it in your reply earlier.
However, I don’t know the icon_value for other tools such as knife cut.

I looked at space_toolsystem_common.py and the icon_value for the toolbar is “icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(item.icon)”.
I found out that the icon_value of the toolbar is related to

However, I don’t know the specific name of the icon_value.
How can I find out the specific name of the icon_value?

Translated with www.DeepL.com/Translator (free version)

        print("idname: " + item.idname.split(".")[1] + "\nicon_value: " + str(icon_value))
        print("----------------------------------------"

I added the above to \2.93\scripts\startup\bl_ui\space_toolsystem_common.py: Line 689 to print out the following (Blender is in edit mode):
----------------------------------------
idname: select_box
icon_value: 975
----------------------------------------
idname: cursor
icon_value: 976
----------------------------------------
idname: move
icon_value: 977
----------------------------------------
idname: rotate
icon_value: 978
----------------------------------------
idname: scale
icon_value: 979
----------------------------------------
idname: transform
icon_value: 980
----------------------------------------
idname: annotate
icon_value: 981
----------------------------------------
idname: measure
icon_value: 982
----------------------------------------
idname: primitive_cube_add
icon_value: 983
----------------------------------------
idname: extrude_region
icon_value: 984
----------------------------------------
idname: inset_faces
icon_value: 985
----------------------------------------
idname: bevel
icon_value: 986
----------------------------------------
idname: loop_cut
icon_value: 987
----------------------------------------
idname: knife
icon_value: 988
----------------------------------------
idname: poly_build
icon_value: 989
----------------------------------------
idname: spin
icon_value: 990
----------------------------------------
idname: smooth
icon_value: 991
----------------------------------------
idname: edge_slide
icon_value: 992
----------------------------------------
idname: shrink_fatten
icon_value: 993
----------------------------------------
idname: shear
icon_value: 994
----------------------------------------
idname: rip_region
icon_value: 995
----------------------------------------
idname: select_box
icon_value: 975
----------------------------------------
idname: cursor
icon_value: 976
----------------------------------------
idname: move
icon_value: 977
----------------------------------------
idname: rotate
icon_value: 978
----------------------------------------
idname: scale
icon_value: 979
----------------------------------------
idname: transform
icon_value: 980
----------------------------------------
idname: annotate
icon_value: 981
----------------------------------------
idname: measure
icon_value: 982
----------------------------------------
idname: primitive_cube_add
icon_value: 983
----------------------------------------
idname: extrude_region
icon_value: 984
----------------------------------------
idname: inset_faces
icon_value: 985
----------------------------------------
idname: bevel
icon_value: 986
----------------------------------------
idname: loop_cut
icon_value: 987
----------------------------------------
idname: knife
icon_value: 988
----------------------------------------
idname: poly_build
icon_value: 989
----------------------------------------
idname: spin
icon_value: 990
----------------------------------------
idname: smooth
icon_value: 991
----------------------------------------
idname: edge_slide
icon_value: 992
----------------------------------------
idname: shrink_fatten
icon_value: 993
----------------------------------------
idname: shear
icon_value: 994
----------------------------------------
idname: rip_region
icon_value: 995
----------------------------------------

Thank you very much for your very kind help.
I have added the code you gave me to line 689 of space_toolsystem_common.py.

Then I got the same output in “Window > Toggle System Console” as you replied, and I was able to check the icon_value.

This is my first time using Python, and there are many things I don’t understand, so thank you very much for your kind help.

“ops.generic.select_box” - this matches the .dat file name,
see “…/2.93/datafiles/icons/” for all the others.

from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
pie.operator(
    "wm.tool_set_by_id",
    text="Move",
    icon_value=ToolSelectPanelHelper._icon_value_from_icon_handle("ops.transform.translate"),
    ).name = 'builtin.move'

Thank you.
Now I see that the names of the icon_values, such as “ops.generic.select_box.dat” are
“D:\Program Files\blender-2.91(MyConfig)\2.91\datafiles\icons”
The name of the icon_value is the same as the file name in
Someone else had told me the same thing before, but I couldn’t figure it out, so…