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.


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():

def unregister():

if __name__ == "__main__":

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.