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?
Bulk Layers Exports to Plain SVGs
Re: Bulk Layers Exports to Plain SVGs
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.
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
-
- Posts: 2344
- Joined: Sun Apr 14, 2013 12:04 pm
- Location: Michigan, USA
Re: Bulk Layers Exports to Plain SVGs
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:
PY:
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:
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/
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/
Re: Bulk Layers Exports to Plain SVGs
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)
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
-
- Posts: 2344
- Joined: Sun Apr 14, 2013 12:04 pm
- Location: Michigan, USA
Re: Bulk Layers Exports to Plain SVGs
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.
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/
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/
Re: Bulk Layers Exports to Plain SVGs
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Re: Bulk Layers Exports to Plain SVGs
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.
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
-
- Posts: 2344
- Joined: Sun Apr 14, 2013 12:04 pm
- Location: Michigan, USA
Re: Bulk Layers Exports to Plain SVGs
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.
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.

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/
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/
Re: Bulk Layers Exports to Plain SVGs
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Re: Bulk Layers Exports to Plain SVGs
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.
-
- Posts: 2344
- Joined: Sun Apr 14, 2013 12:04 pm
- Location: Michigan, USA
Re: Bulk Layers Exports to Plain SVGs
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/
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/
-
- Posts: 2344
- Joined: Sun Apr 14, 2013 12:04 pm
- Location: Michigan, USA
Re: Bulk Layers Exports to Plain SVGs
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.
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.
- 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/
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/
Re: Bulk Layers Exports to Plain SVGs
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.

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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)