Icon Enumeration Script (Blender 2.5)

I’ve started to learn Blender 2.5 scripting these days, and I’m trying to create a brief script that shows all icons that Blender 2.5 has only out of my curiosity. I want to learn especially about the new UI system of Blender 2.5 and I hope that I can get a lot of experience and useful knowledge with this small challenge.

Here is the script, the latest version 3. It allows you to search for the icon name.

The part of the code “icon_list = […]” is too long to list up all icon names, so I shortened. The complete code is available to download from here: 92 icon_enum_test3.py


import bpy


global_icon_list = ['BLENDER', 'QUESTION', 'ERROR', 'CANCEL']

class ParamSet(bpy.types.IDPropertyGroup):
    
    search_text = bpy.props.StringProperty(default="", name="Search", description="Search name of icon")
    column_count = bpy.props.IntProperty(min=1, max=50, default=2, name="column", description="Displayed column count")
    
    searched_text = None
    searched_icon_list = []

bpy.types.Scene.icon_enum_param_set = bpy.props.PointerProperty(type=ParamSet)
param_set = bpy.data.scenes[0].icon_enum_param_set

class OBJECT_PT_IconEnum(bpy.types.Panel):
    
    bl_label = "Icon Enumeration"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        
        self.setup_icon_list()
        icon_list = param_set.searched_icon_list
        
        col = layout.column()
        col.prop(param_set, "search_text")
        col.label("%d icons are shown." % len(icon_list))
        col.prop(param_set, "column_count")
        
        row = layout.row()
        col_count = param_set.column_count
        col_list = [row.column() for i in range(col_count)]
        for i, icon_name in enumerate(icon_list):
            col_list[i % col_count].label(text=icon_name, icon=icon_name)

    def setup_icon_list(self):
        
        if param_set.searched_text == param_set.search_text:
            return
        param_set.searched_text = param_set.search_text
        
        search_list = param_set.search_text.split(" ")
        search_list = [x.upper() for x in search_list if len(x) > 0]
        print("DEBUG:", len(search_list))
        
        param_set.searched_icon_list = []
        icon_list = param_set.searched_icon_list
        for icon_name in global_icon_list:
            
            if icon_name.startswith("BLANK"):
                continue
            
            is_all_found = True
            for search_text in search_list:
                if icon_name.find(search_text) < 0: # if: not found
                    is_all_found = False
                    break
            if is_all_found:
                icon_list.append(icon_name)
            
if __name__ == '__main__':
    pass

To run the code:

  1. Copy the code and paste it into the text panel (the upper left frame in the Scripting layout in Blender 2.5)
  2. Click the Run Script button
  3. Click the Object properties icon in the buttons panel (it appears as a tiny cube)
  4. Scroll down to see a panel named Icon Enumeration

Screenshot:
http://1.bp.blogspot.com/_d4nbesSwQqc/TM0H5sDrQgI/AAAAAAAAAxk/lSkXyM_yksY/s1600/00062.JPG
The picture shows the result when “right” is typed in the Search box.

http://3.bp.blogspot.com/_d4nbesSwQqc/TM0H6Lj1xeI/AAAAAAAAAxo/n8ukQsyT0sE/s1600/00062.png

Crouch already created the same script at http://blenderartists.org/forum/showthread.php?t=164765&page=3, but this is my version and I want to share it with everyone :slight_smile:

1 Like

Here is the very first script version 1. It will show all icons and do nothing more.

The part of the code “icon_list = […]” is too long to list up all icon names, so I shortened. The complete code is available to download from here: 90 icon_enum_test.py


import bpy


icon_list = ['BLENDER', 'QUESTION', 'ERROR', 'CANCEL']

class OBJECT_PT_IconEnum(bpy.types.Panel):
    
    bl_label = "Icon Enumerate"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        
        col = layout.column()
        for icon_name in icon_list:
            
            if icon_name.startswith("BLANK"):
                continue
            
            col.label(text = icon_name, icon = icon_name)

if __name__ == '__main__':
    pass

Screenshot:
http://4.bp.blogspot.com/_d4nbesSwQqc/TMzfp5oRpoI/AAAAAAAAAxI/Rws_CgXNUFM/s1600/00060.JPG

I’m still working on the scripting for the icon enumeration. Here is version 2 in which the icons are shown in multi columns. You can specify the number of columns.

The part of the code “icon_list = […]” is too long to list up all icon names, so I shortened. The complete code is available to download from here: 91 icon_enum_test2.py


import bpy


icon_list = ['BLENDER', 'QUESTION', 'ERROR', 'CANCEL']

class ParamSet(bpy.types.IDPropertyGroup):
    
    column_count = bpy.props.IntProperty(min=1, max=50, default=2, name="column", description="Displayed column count")

bpy.types.Scene.icon_enum_param_set = bpy.props.PointerProperty(type=ParamSet)
param_set = bpy.data.scenes[0].icon_enum_param_set

class OBJECT_PT_IconEnum(bpy.types.Panel):
    
    bl_label = "Icon Enumeration"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        
        col = layout.column()
        col.prop(param_set, "column_count")
        
        row = layout.row()
        col_count = param_set.column_count
        col_list = [row.column() for i in range(col_count)]
        i_label = 0
        for icon_name in icon_list:
            
            if icon_name.startswith("BLANK"):
                continue
            
            col_list[i_label % col_count].label(text=icon_name, icon=icon_name)
            i_label += 1

if __name__ == '__main__':
    pass

Screenshot:
http://3.bp.blogspot.com/_d4nbesSwQqc/TMzpinxkFkI/AAAAAAAAAxg/CMJWM4pbgD0/s1600/00061.JPG

1 Like

Using the script “91 icon_enum_test2.py”, I drew all icons and made pictures so that I can see all icons and names. Please use them as a reference for your work :slight_smile:




2 Likes

Here is version 3 that allows you to search for the icon name.

The part of the code “icon_list = […]” is too long to list up all icon names, so I shortened. The complete code is available to download from here: 92 icon_enum_test3.py


import bpy


global_icon_list = ['BLENDER', 'QUESTION', 'ERROR', 'CANCEL']

class ParamSet(bpy.types.IDPropertyGroup):
    
    search_text = bpy.props.StringProperty(default="", name="Search", description="Search name of icon")
    column_count = bpy.props.IntProperty(min=1, max=50, default=2, name="column", description="Displayed column count")
    
    searched_text = None
    searched_icon_list = []

bpy.types.Scene.icon_enum_param_set = bpy.props.PointerProperty(type=ParamSet)
param_set = bpy.data.scenes[0].icon_enum_param_set

class OBJECT_PT_IconEnum(bpy.types.Panel):
    
    bl_label = "Icon Enumeration"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        
        self.setup_icon_list()
        icon_list = param_set.searched_icon_list
        
        col = layout.column()
        col.prop(param_set, "search_text")
        col.label("%d icons are shown." % len(icon_list))
        col.prop(param_set, "column_count")
        
        row = layout.row()
        col_count = param_set.column_count
        col_list = [row.column() for i in range(col_count)]
        for i, icon_name in enumerate(icon_list):
            col_list[i % col_count].label(text=icon_name, icon=icon_name)

    def setup_icon_list(self):
        
        if param_set.searched_text == param_set.search_text:
            return
        param_set.searched_text = param_set.search_text
        
        search_list = param_set.search_text.split(" ")
        search_list = [x.upper() for x in search_list if len(x) > 0]
        print("DEBUG:", len(search_list))
        
        param_set.searched_icon_list = []
        icon_list = param_set.searched_icon_list
        for icon_name in global_icon_list:
            
            if icon_name.startswith("BLANK"):
                continue
            
            is_all_found = True
            for search_text in search_list:
                if icon_name.find(search_text) < 0: # if: not found
                    is_all_found = False
                    break
            if is_all_found:
                icon_list.append(icon_name)
            
if __name__ == '__main__':
    pass

Screenshot:
http://1.bp.blogspot.com/_d4nbesSwQqc/TM0H5sDrQgI/AAAAAAAAAxk/lSkXyM_yksY/s1600/00062.JPG
The picture shows the result when “right” is typed in the Search box.

http://3.bp.blogspot.com/_d4nbesSwQqc/TM0H6Lj1xeI/AAAAAAAAAxo/n8ukQsyT0sE/s1600/00062.png

2 Likes

nice one and easy to find with name!

thanks for sharing this

happy 2.5

>>RickyBlender: Thank you. The script has nothing new, but I hope someone find it useful.

This is really cool!

Nice and useful. Thanks for the picture reference!

Thank you, Ben Elef.
Actually I found Blender 2.56 has a similar addon called Icon in System: category. It’s very simple so it would be a good addon sample code to get started with Blender 2.5x addon scripting.

1 Like

hans

have you the point cloud skinner for 2.5 ?

Thanks

My dev plan is:

  1. CSV F-Curve Importer
  2. CSV Mesh Importer
  3. Point Cloud Skinner

Now it’s called “Icon Viewer” under “Development” category :slight_smile: