I just made a 3-layer file to investigate the structure, each layer containing a simple geometric figure.
The result has a header, which ends in
</metadata>
Then, for each layer, a block (here shown for layer 1):
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<CONTENT/>
</g>
The part of CONTENT would be one of your files, stripped from its header and from its SVG-close-tag.
Ended with the overall SVG-close-tag.
</svg>
Okay, what would be the most comfortable way to use such a script? You have to specify a filename for the final result and the files for the layers. It could be convenient to work with file name patterns in the shell like
layerize.sh result.svg board*.svg
Caution:
This is a raw solution which might fail under special conditions and is not sanitized against common errors, like missing or wrong parameters. It might fail with duplicated Group-IDs and so on from different files.
My first approach worked for simple figures, but not for gradients and so on. So I have a new workflow:
- Open a new, empty SVG file.
- import all the images you like to distribute over different layers at once. This should include all gradients, filters and definition you need.
- save this file as "layerstemplate.svg"
Now use this modified script:
#!/bin/bash
result=$1
shift
test -e $result && echo "file exists!" && exit 1
# takes everything, up to the closing "metadata" tag from the template:
header () {
sed -n '1,/<\/metadata>/p' ./layertemplate.svg
}
count=0
layer () {
((count +=1))
echo -e " <g
inkscape:label=\"Layer $count\"
inkscape:groupmode=\"layer\"
id=\"layer$count\">"
sed '1,/<\/metadata>/d;$d' "$1"
echo -e " </g>"
}
header > "$result"
# iterates over all (remaining) parameters
for f
do
layer "$f" >> "$result"
done
echo "</svg>" >> "$result"
I did not try it with sources, which use layers themselves and have no idea how I would handle it. So far, I don't plan on improving this further, but feel free to make suggestions, to criticize it and ask questions.