Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

May 20, 2015

Custom icons in Blender Add-on scripts

Note to self

How to do this once you have the icons can be read here: ui_previews_custom_icon.py

It's surprisingly simple, and brings a whole new world of potentially ugly icons. Icon design isn't something I'm super interested in, but I have had some desire to make icons for tinyCAD's mesh ops.

The tinyCAD custom icon branch is available from github, but to be honest i'm not sure the ability to add icons really makes a difference to tinyCAD - or maybe my icons suck :) Using ImageMagick's convert.

Here's what it looks like:
import os
import subprocess

def generate(from_file, x, y, filenames, type='.png'):
    filenames = filenames.split()
    with open('local01.tff', 'w') as m:
        print('generated local file')

    yield "convert {0} local01.miff".format(from_file)
    for i, filename in enumerate(filenames):
        l = "convert local01.miff -crop {0}x{1}+{2}+0 {3}{4}"
        yield l.format(x, y, i * x, filename, type)
    yield "rm local01.miff"

def main():
    rendered_name = 'RENDERED_ARRAY.png'
    file_strings = generate(rendered_name, 32, 32, icons)
    for line in file_strings:


This doesn't work flawlessly with windows systems. At the time of writing I was using ubuntu.


  1. Allows this script to use a list of single images or have we only the ability to create a image sprite for each single addon?
    Can you great an example with the default templates (ui_previews_custom_icon.py)
    or a download of the tinycad addon for study? It will be very handy...

    1. You don't have to use any slicing program like ImageMagick convert / crop. That's merely how I did it this time. I rendered the icon-sheet and then sliced automatically. You could render each separately. You can test the icon version of tinyCAD by checking out the icons branch : https://github.com/zeffii/Blender_CAD_utils/tree/icons ( you can browse the code instead of installing it)

    2. I have testing it! It works great!
      And after i made a registered panel with the default template, i know how to use it!
      Thank you!


Please use Blender.StackExchange.com for python scripting questions unrelated to this post.