This post has been updated for Blender 2.55 build 32738
Icons
Since it is hard to find which icons there are to use, I’ve written a script to display them along with their names (mouse-over for a tooltip, click to print to the console). These are the names that are used to draw them in the GUI (take a look at the “Hello world” script for an example).
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_addon_info = {
'name': 'Icons',
'author': 'Crouch, N.tox, PKHG',
'version': (1, 3, 1),
'blender': (2, 5, 5),
'api': 32738,
'location': 'Properties window > Object tab',
'warning': '',
'description': 'Creates a panel displaying all icons and their names.',
'wiki_url': '',
'tracker_url': '',
'category': 'System'}
import bpy
import urllib.request
# create list with all icon names
def createIcons():
# retrieving the masterlist with all icon names
try:
file = urllib.request.urlopen('https://svn.blender.org/svnroot/'\
'bf-blender/trunk/blender/source/blender/editors/include/UI_icons.h')
except:
print("Couldn't find the urllib module or was unable to connect to"\
" the internet")
file = ''
# get the icon names of existing non-blank icons
icons = [str(l)[11:(-4 if l[-2]==b')' else (l.index(b')')+2))] for l in \
file if ( (l[:9]==b'DEF_ICON(') and (l[9:19]!=b'ICON_BLANK') )]
icons.sort()
return icons
# create custom operator for each icon
def createOperators(icons):
for i in icons:
class custom_op(bpy.types.Operator):
bl_idname = "ICONDISPLAY_OT_"+i
bl_label = "ICONDISPLAY_OT_"+i
bl_description = i
def invoke(self, context, event):
print(self.bl_description)
return {'FINISHED'}
# main function that calls subroutines
def main():
icons = createIcons()
createOperators(icons)
# draw the panel with the icons
class OBJECT_PT_icons(bpy.types.Panel):
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
bl_label = "All icons"
icons = createIcons()
def draw(self, context):
amount = 10
cols = []
layout = self.layout
split = layout.split(percentage=1.0/amount)
for i,icon in enumerate(self.icons):
if i<amount: cols.append(split.column())
col = cols[i%amount].row()
try:
col.operator("icondisplay."+icon, text="", icon=icon)
except:
col.operator("icondisplay."+icon, text="new")
main()
def register():
pass
def unregister():
pass
The script needs a connection to the internet (to retrieve the source file in which all icons are named) and might need a full python install. The result can be seen at the bottom of the Object properties (just like the “Hello world” and “Ping pong” scripts), in its own panel called “All icons”.
Analysis
There isn’t much new in this script, but I’ll do a quick rundown on it.
createIcons() is a function to retrieve the source file from the internet and get the icon names in a list. This list (named ‘icons’) is used by the rest of the script.
createOperators() creates a custom operator class for each icon and registers it with blender. The reason I did this, is so that each icon can have its own tooltip (bl_description string). It might be dirty and not the best way to achieve this, but it was the only way I could think of.
What is new (compared to revision 22647) is that you can now define operators outside of the predetermined groups (like object, texture, world, ect.). You can create new groups by defining them in the idname of the new operator. It works like this:
bl_idname = MYNEWGROUP_OT_mynewoperatorname
You can then call it by using ‘mynewgroup.mynewoperatorname’ (as seen in line 47). Alternatively you can just store the operator at the highest level (among the operator groups, though this can quickly become a mess with name collisions) by using a random operator name:
bl_idname = mynewoperatorname
The last part is the class that actually draws the panel. I’ve chosen for a simple layout, with the amount of columns defined in line 49 (amount = 10). Any amount will work, but you’ll have to broaden the default panel width a bit to display more than 6 columns correctly.
As you can see I’m using operator() (operator pushbuttons) and not label() (simple labels). label() would also work to display the icons, but can’t display tooltips.