Embedding icons in GhPython code

Sometimes, when developing GHPY files, you might need to embed icons in the Python file. There are a few alternatives, but a simple one is to just create the picture from a string, if the picture is small by itself.

For example, this base-64 string:

iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAOwgAADsIBFShKgAAAAUpJREFUSEvtlL0rRWEAh4+vQRhsVtmsGNj8DRKLFWWQQSll8QeIUkrZ
DAYbq0WUksGuLAaLUcjX89z3fXW77j2cmzuo+9TT+zvvqfd3Pt5zsib10hPHRGccKymf74pjLsP4
hB+4in34HI/fcAjF45c4bqHnzHuYywIuhviNOVwJsbTYYIjZA46EmN1ia4jV8ZZ38QxHnQCv8BFd
dM0JMCdu4ihX2B1iPjN4ghO46QTMYip4j6MUKthGr07ncQDT83XRandQmX+8g15sC/GLWrvo/zEW
x4axg+MhNoY/K/CLdpv6Vbt71lHKCzbQHeb5KSeKYMFdiCXSVkwFk3jhBPheTkP8PRYchljiEvsx
FSyjpdd4jsdYCAv8ryRcrAVTwTT6iOrGgnt8RRdfQil/BwfoOfVdFMKCI2xHr7wWHeiXXxgL9kNs
0lCy7BP8OEoIkC0vEAAAAABJRU5ErkJggg==

can be parsed to this image:


sample , a 24x24 pixel png icon.


This definition translates the bitmap representation to the text representation, and back.

This definition was made by request here.

icon-to-text-for-python.gh (12.2 KB)

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

4 Likes