A python script that reads a SVG file and creates based on specific attributes in the layers new files where the layers are or aren't shown. This might come in handy if you need different versions of your svg based on different layer visibilities.
You need either python 2.7 or python 3.7 installed on your local machine; and also Inkscape. Other than that you are good to go.
Add a custom node at layer level in the xml file of your inkscape file. For Example, in
Line 87 in ff216f3
exercise
of the value a,b-c,d-e
since I am using this feature mainly for creating exercises for students.
But no worries, you can choose whatever name you want for the custom node. It ist just important, that you seprated your values with a ,
since this is the default delimiter. But it can, as the name for the node, be changed.
If layers do not have this customnode, they will always be shown. If you want to have a layer just in your "Master" svg and nowhere else, put in the custom node the value never
or Never
.
If a file has no instance of the custom node in all layers no operation will executed.
python hideAndShowLayers.py --help
displays the possible options you can set.
python hideAndShowLayers.py
runs the script in the current folder. It will search for *.svg
files and then for their layers. The default node identifier at layer lever is exercise
. If in the whole file no such node exist the program will skip the current svg
file. As soon as there is one instance it will create new svgs
with a $combination_modLayer
suffix, where $combination
represents the current combination of showing and hiding layers.
The files just_a, just_b-c, just_d-e, and the original file give the visual representation how the layers will we hidden and shown after running the script. This file has no identifier at all and will be excluded from the modifications.
If you rerun the script, it will omit all files that contain *modLayer*
in order to prevent creating too many files.
python hideAndShowLayers.py -a website -d ; -s modifiedLayer -o ./Output -f ./RawSVG
will run the script with all possible optinal arguments. It does the same as before but now the custom node identifier has the name website
, the new delimter for the different versions is ;
, the suffix that will be added is $combination_modifiedLayer
, all outputfiles will be saved in the folder ./Output
, and the programs searches for files in ./RawSVG
.
This program was tested with Python 2.7.15
, Python 3.7.1
and Inkscape 0.92.3
.
- xml.etree.ElementTree - The ElementTree XML API
- argparse - Parser for command-line options, arguments and sub-commands
This project is licensed under the MIT License - see the LICENSE.md file for details