This works for class panel. But i would like to use this new icon in the main tool section, using the workspacetool class.
From all the examples i have seem bl_icon attribute needs string to select the icon.
While the way i saved the image is in a class called ImagePreview. I have noticed all the workspacetools icons are located in a icons file in blender, but all the icons has .dat extension which i don’t know how is the data saved. Any idea on how to solve this?
Welcome to Devtalk You’re right that you can’t just pass the string 'custom_icon' to the icon parameter of UILayout functions.
After calling custom_icons.load(identifier) you can use custom_icons[identifier].icon_id, which gives you an integer that you can pass to the icon_value parameter:
layout.label(text='Blender Sync with Blender Cloud', icon_value=custom_icons['custom_icon'].icon_cd)
On a side note about, generally code-style wise speaking, I would recommend against changing the type of variables. In the example code you posted, custom_icons is declared as dict, but later is assigned an object of a different type. This can cause confusion, so it’s better to initialise to None instead. You can then annotate it with an explicit type:
from typing import Optional
import bpy.utils.previews
custom_icons: Optional[bpy.utils.previews.ImagePreviewCollection] = None
This is what i foound. WorkSpaceTool uses .dat files as icons and you can find all icon .dat in the icon folder. In order to create your .dat you need to create it using the following script: