Automated Android graphics creation with Inkscape

After creating new graphics for most every UI element in Recipe Convert Pro in Inkscape I just could not bring myself to manually create all of the individual sizes of each of the individual button states. That would have been around 150 graphics files that I would have to export one at a time, setting the size & selecting the target directory for each. I needed a way of automating Automated Android graphics creation with Inkscape.

Instead, I opted to spend a couple of hours researching how I could automate this. Happily I found that Inkscape has a scriptable API. Having never written a Windows batch file I had to read up on that a bit. Below is the result.

Basically the way it works is I start from the directory I will have the Inkscape SVG in by creating the same applicable subdirectories that are in the Android project “res” directory “ldpi”, “mdpi”, “hdpi”, and “xhdpi”. I then start my file in Inkscape in that directory and set the page size to the same pixel dimensions as the desired MDPI dimensions.

(“Eye of the Tiger” blaring over time lapse montage of making graphics…)

Once I have my graphics ready I will group the elements for each state and give them an appropriate ID such as “normal”, “focused”, or “pressed”. At this point I can drag and drop the SVG file on the bat file. The script will then do all of the necessary scaling and exportation into the appropriate subdirectories that were created in the first step.

Hope someone else finds this as useful as I have! Drop a comment below with any questions or comments!