Splitting Inkscape SVG Layers

Yesterday I hit a problem, that I was not able to solve with any free tools that I could find. I wanted to take a SVG with several layers, that I created in Inkscape, and split it into several SVGs with one layer each. And I wanted to be able to do that quickly on the commandline.

A quick web search lead me a blog post where a script written in Haskell is shown that does just that. I had some problems getting it to work, because I am not familiar with the haskell module system. As it didn't look to complicated, I looked at a typical SVG file, and discovered that the structure is pretty easy. It took only a few minutes to hack together a small python script that does the job. It isn't particularly robust, and probably breaks in many situations, because I did not look at the SVG specs.

However, I find it amazing that Python allows me to write a solution for my problem in 63 lines (including license header) in only a few minutes. For those that are interested, I put the code in a github repository.