Skip to content
Berteh edited this page Apr 21, 2015 · 20 revisions

svg-objects-export

Usage examples

Interesting usage examples to integrate in your own workflows: (please contribute!)

  • To export all "group" objects with an id or label that has been modified in inkscape, as long as the id and label don't match: ./svg-objects-export.py --xpath "//svg:g[@inkscape:label!=@id]" input.svg

  • To export all layers of a file in the area of the page first make sure all layers are visible (yes: all at the same time!), save and run: ./svg-objects-export.py --xpath "//svg:g[@inkscape:groupmode='layer']" --extra '--export-area-page --export-id-only' input.svg

  • To export all "root" groups in Inkscape, i.e. all groups with an id that starts with g that have no parent group with an id that starts with g explanation:: ./svg-objects-export --xpath "//svg:g[re:test(@id, '^g', 'i')][ not(../../svg:g[re:test(@id, '^g', 'i')]) ]" -d groupWithNoParentGroup/ in.svg

Exporting from Plain SVG (or SVG from other applications)

The examples above rely on the inkscape extensions of SVG (The default inkscape format). They won't work with plain svg files (where, a.o. the concept of layers doesn't exist) or SVG files from other software, where you should rely only on valid SVG elements (see SVG specification), or use a specific id naming scheme.

For instance, if you rename all your layers id into "layer1", "layer2",.. "layer25", then you can export them using the following command:

svg-objects-export --pattern "^layer" --extra " --export-id-only" in.svg

Install on Mac

Some users may get the following error when using the terminal of Mac OS: ImportError: No module named lxml" on Mac

It's fixed easily as per http://stackoverflow.com/questions/22674730/importerror-no-module-named-lxml-on-mac#22692262

sudo easy_install pip sudo pip install lxml

(Yes, sudo is required.) That takes a few seconds and BAM! It works (at least it did for dueddel).

Export to SVG objects

Using this script to export to SVG objects is currently limited by Inkscape poor support for this function. Basically: it works with a recent version of inkscape, but not all transformations (eg zoom, move) are applied correctly, leading to the exported objects being out of the bounding (display) box.

It is on the agenda of the Inkscape developpers (see bug report #1306662), there's nothing I can do to help.

Complementary tools

  • To turn the png into jpgs from command line there is imagemagick: (careful: mogrify command overwrites files without warning) mogrify -format jpg -quality 100 *.png
Clone this wiki locally