Is there a way to get the icon_value of a material for use with a UIList? When using a UIList with bpy.data.materials as the target list, the icon value seems to be passed to the draw function, but I'm not seeing a way to get the integer ID myself from bpy.data.materials.
1 Answer
You can get the icon value from the UILayout classmethod icon
Example using the simple panel template.
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
mat = obj.active_material
layout.label(mat.name, icon_value = layout.icon(mat))
def register():
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()