Bulk Layers Exports to Plain SVGs

Post questions on how to use or achieve an effect in Inkscape.
chiefzdn
Posts: 2
Joined: Thu May 04, 2017 3:39 pm

Bulk Layers Exports to Plain SVGs

Postby chiefzdn » Thu May 04, 2017 3:43 pm

Hello everyone,

I've seen bulk layers exports, but to JPG/PNG. It's not good since those are raster files. I've one question. How to bulk layers exports to plain SVG files?

theozh
Posts: 437
Joined: Fri Mar 23, 2012 6:30 pm

Re: Bulk Layers Exports to Plain SVGs

Postby theozh » Thu May 04, 2017 6:00 pm

Welcome @chiefzdn to the forum!
Have you checked this post? viewtopic.php?f=5&t=9516
However, the OP of that post did not state whether the suggested solutions worked for him and if his question was actually solved.
Win7/64, Inkscape 0.92.2

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Bulk Layers Exports to Plain SVGs

Postby tylerdurden » Thu May 04, 2017 11:38 pm

I tried running that script (layer2svg.py) via windows command line and didn't get any output, but I'm most probably doing it wrong.

I also tried making it into an extension and I'm definitely doing it wrong.

Odd thing is that the bad extension I pasted together actually outputs files (to the user extension directory!), AND crashes Inkscape in the process.

INX:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
    <_name>Export Layers to SVG</_name>
    <id>net.kaleidos.export.SVGlayers</id>
    <dependency type="executable" location="extensions">layer2svg.py</dependency>
   <param name="help" type="description">Export your file in different SVG files by layer</param>
    <effect needs-live-preview="false">
        <object-type>all</object-type>
        <effects-menu>
            <submenu _name="Export" />
        </effects-menu>
    </effect>
    <script>
        <command reldir="extensions" interpreter="python">layer2svg.py</command>
    </script>
</inkscape-extension>


PY:

Code: Select all

#! /usr/bin/python3
import xml.etree.ElementTree as ET
import copy
import sys

tree = ET.parse(sys.argv[1])
root = tree.getroot()
listoflayers=[]
for g in root.findall('{http://www.w3.org/2000/svg}g'):
    name = g.get('{http://www.inkscape.org/namespaces/inkscape}label')
    listoflayers.append(name)
print(listoflayers)
try:
    listoflayers.remove('background')
except ValueError:
    print("No background")
for counter in range(len(listoflayers)):
    james=listoflayers[:]
    temp_tree = copy.deepcopy(tree)
    del james[counter]
    print(james)
    temp_root = temp_tree.getroot()
    for g in temp_root.findall('{http://www.w3.org/2000/svg}g'):
        name = g.get('{http://www.inkscape.org/namespaces/inkscape}label')
        if name in james:
            temp_root.remove(g)
    temp_tree.write(listoflayers[counter]+'.svg')




Any suggestions?
This seems like a handy thing to have as an extension, so I'm willing to muck about with it...

Test file attached:
Attachments
test-svg.svg
(7.98 KiB) Downloaded 214 times
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Bulk Layers Exports to Plain SVGs

Postby Moini » Fri May 05, 2017 1:13 am

I think there are a couple of extensions that do that already.... Let me do a web search...
https://github.com/kristofvandam/inkscape-batch-export
https://github.com/james-bird/layer-to-svg
http://svgsplit.com/ (not an extension, standalone - code available on github)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Bulk Layers Exports to Plain SVGs

Postby tylerdurden » Fri May 05, 2017 1:21 am

Hi,
the James Bird code is a python script, that's what I'm struggling with... can't get output running the script via win CMD (probably not running it properly), pasting stuff together as an extension crashes inkscape and puts the files in the extensions folder.

I'm just taking potshots.
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Bulk Layers Exports to Plain SVGs

Postby Moini » Fri May 05, 2017 1:50 am

Right, it's not an extension... Sorry, hadn't really checked :-/ Does the extension work? (I mean, the real one, the first link)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Bulk Layers Exports to Plain SVGs

Postby Moini » Fri May 05, 2017 1:52 am

And no, the script is using python3, while Inkscape is running python2 - you'd have to backport the script, if there are any incompatibilities.
I'm not sure about all that namespace stuff, it works differently for the extensions I've seen up to now.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Bulk Layers Exports to Plain SVGs

Postby tylerdurden » Fri May 05, 2017 8:02 am

I didn't try the kristofvandam extension, since it stated the viewbox would be a problem.

The Bird script hacked into an extension template does output separate svg files for each layer, but with noted significant issues. I was hoping those issues were due to some missing bits that could be easily pasted into the code. :lol:
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Bulk Layers Exports to Plain SVGs

Postby Moini » Fri May 05, 2017 10:43 am

There is a keyboard shortcut option/menu item now for 'resize page to content'. Keyboard shortcuts/menu items are equivalent to Inkscape command line verbs. This, if used in an extension, could solve the viewbox issue.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

chiefzdn
Posts: 2
Joined: Thu May 04, 2017 3:39 pm

Re: Bulk Layers Exports to Plain SVGs

Postby chiefzdn » Fri May 05, 2017 11:11 am

Moini wrote:I think there are a couple of extensions that do that already.... Let me do a web search...
https://github.com/kristofvandam/inkscape-batch-export
https://github.com/james-bird/layer-to-svg
http://svgsplit.com/ (not an extension, standalone - code available on github)


I can't install the Batch Export extension correctly since I using Snap version of Inkscape. The doc say, 'show in Extensions>Export' but I can't get it.

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Bulk Layers Exports to Plain SVGs

Postby tylerdurden » Fri May 05, 2017 12:02 pm

Moini wrote:There is a keyboard shortcut option/menu item now for 'resize page to content'.

Thank you... good to know. That button in the preferences panel is hard for some folks to find.
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

tylerdurden
Posts: 2344
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Bulk Layers Exports to Plain SVGs

Postby tylerdurden » Sat May 06, 2017 11:58 am

Well, the Vandam batch extension generates output, but maybe useful only in limited ways.

It seems the output of the Vandam extension only generates a 100x100 page, with objects correct scale, but improper location.

A batch export in it's best implementation (IMO) would maintain page size and object scale/location.

Not sure how sizing page to selection can be useful without a page size object in each layer; unless just the layers/objects divorced from other context are useful.
batchResult.png
batchResult.png (244.78 KiB) Viewed 2258 times
Attachments
test-svg.svg
Updated with blue rectangle.
(8.53 KiB) Downloaded 154 times
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Bulk Layers Exports to Plain SVGs

Postby Moini » Sat May 06, 2017 12:18 pm

For some, it may be useful to have the 'resize to object size' option, so maybe having both options available as radio buttons would make sense :)
Some people export icons and such, which may be of different sizes.
Probably being able to either batch export layers (nothing selected) or objects (selected objects) would be a nice addition, too.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “Help with using Inkscape”