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'
    icons = "VTX V2X XALL BIX PERP CCEN EXM"
    file_strings = generate(rendered_name, 32, 32, icons)
    for line in file_strings:
        subprocess.Popen(line.split())


main()

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