Dear Inkscape communty. I created a large drawng file with many objects separated in layers. My target is to automatically separate layers into files (this is how my input file looks like https://imgur.com/a/lgygOMr)
I can export layers using the python script https://github.com/james-bird/layer-to-svg , however the new files keep the old huge page dimension and the objects keep their position within that canvas.
At the moment I have to open each file separately, select all objects, choose "Edit-> Page size to selection" (or press SHIFT+CTRL+R) and save that file.
Is there also a possibility to do it over the command line?
Actually export-id should do the job, bit saddly it only works on object id(s), not on Layer id.
Thanks, @inklinea. Logically it seems to be the right thing. Unfortunately, on my file it produces strange results. I will try around and report if I manage something to get working.
I think I found the problem, but no solution yet :)
If I look at the source of my svg, I see that not every layer has the attribute inkscape:groupmode="layer" although I used "create new layer" every time.
This is strange, since the GUI can somehow restore the hierarchy, obviously without using the "groupmode" attribute. If you convert text into shape, there is a group as well as if you group objects. Those groupings become indistinguishable from layers. It might be a bug of inkscape not to label things correctly. I also noticed that renaming of layers is quite buggy. Sometimes it works, other times it changes, but the old name is displayed.
Not sure how to proceed at the moment. Is there a way to manually label layers? I mean, I can do it in the source file, of course, but having it directly in inkscape would be more the right thing..
I'm not 100% sure about the labelling of layers, normall I would just click on the layer name and type - but is it essential that you press enter after typing or it will not register.
Also you can convert groups to layers by clicking the circled icon in the Object>Objects panel.
Ah, thank you for that tip. Yes, it helps. When all Layers are annotated correctly, your script works.
Of course, it is only exporting the top Layers and the file names are based on layerIds. But for splitting into layers with no tools other than inkscape it is the right way. Thanks!
Also if I export into svg, It would keep the whole Layer structure. So splitting in files and re-issue the script on splits would not help.
I am not sure, whether the complex operations that I need (selecting, combining and exporting using the layer hierarchy information) would be indeed something for an XML editor (in fact in the meanwhile I started to write something in python)
PS: Regarding renaming - unfortunately, neither text/Enter, nor "Rename" works reliably. Sometimes you can click into a name, sometimes it won't let you to. Sometimes if you click away it changes the name, sometimes it does not. What I am doing now is a "blind" renaming, ignoring the wrong display than save and re-open the file (some names appear correct after this) and continue with names which were not renamed..... When I have some file which I can publish here, where this behavior occurs, I will post...
Dear Inkscape communty. I created a large drawng file with many objects separated in layers. My target is to automatically separate layers into files (this is how my input file looks like https://imgur.com/a/lgygOMr)
I can export layers using the python script https://github.com/james-bird/layer-to-svg , however the new files keep the old huge page dimension and the objects keep their position within that canvas.
At the moment I have to open each file separately, select all objects, choose "Edit-> Page size to selection" (or press SHIFT+CTRL+R) and save that file.
Is there also a possibility to do it over the command line?
Actually export-id should do the job, bit saddly it only works on object id(s), not on Layer id.
This works:
inkscape --export-type="svg" --export-id="path3670" -o output.svg input.svg
But this does not:
inkscape --export-type="svg" --export-id="Layer1" -o output.svg input.svg
Also having the possibility to write out Layer would make the python script obsolete
Thank you!
Sergej
Update, ok, I found how to fix it, it may be useful for others. This will do the job:
inkscape --export-type="svg" --export-area-drawing -o input.svg output.svg
Still, working with Layers (even better with cascading Layers like Layer1.SubLayer1) from commandline would make this more fine ganular...
What os are you using ?
I am on Ubuntu 20.04.3 LTS (Focal Fossa)
I assume you know how to paste text into a file and save it as
'export-layers.sh'
thenchmod +x
to make it executable ?then
./export-layers.sh ./drawing.svg
Put the following in the file - it might work or might not
readarray array <<< cut -d ' ' -f 3 <<< $(inkscape --actions="select-all:layers;select-list" $1)
for i in "${array[@]}"
do
#echo $(cut -d ' ' -f 1 <<< $i)
object=$(cut -d ' ' -f 1 <<< $i)
$(inkscape --batch-process --actions="select-by-id:$object;select-invert:layers;EditDelete;export-area-drawing;export-filename:exportedLayer_$object.png;export-do" $1)
done
Thanks, @inklinea. Logically it seems to be the right thing. Unfortunately, on my file it produces strange results. I will try around and report if I manage something to get working.
I think I found the problem, but no solution yet :)
If I look at the source of my svg, I see that not every layer has the attribute inkscape:groupmode="layer" although I used "create new layer" every time.
This is strange, since the GUI can somehow restore the hierarchy, obviously without using the "groupmode" attribute. If you convert text into shape, there is a group as well as if you group objects. Those groupings become indistinguishable from layers. It might be a bug of inkscape not to label things correctly. I also noticed that renaming of layers is quite buggy. Sometimes it works, other times it changes, but the old name is displayed.
Not sure how to proceed at the moment. Is there a way to manually label layers? I mean, I can do it in the source file, of course, but having it directly in inkscape would be more the right thing..
I'm not 100% sure about the labelling of layers, normall I would just click on the layer name and type - but is it essential that you press enter after typing or it will not register.
Also you can convert groups to layers by clicking the circled icon in the Object>Objects panel.
Ah, thank you for that tip. Yes, it helps. When all Layers are annotated correctly, your script works.
Of course, it is only exporting the top Layers and the file names are based on layerIds. But for splitting into layers with no tools other than inkscape it is the right way. Thanks!
Also if I export into svg, It would keep the whole Layer structure. So splitting in files and re-issue the script on splits would not help.
I am not sure, whether the complex operations that I need (selecting, combining and exporting using the layer hierarchy information) would be indeed something for an XML editor (in fact in the meanwhile I started to write something in python)
PS: Regarding renaming - unfortunately, neither text/Enter, nor "Rename" works reliably. Sometimes you can click into a name, sometimes it won't let you to. Sometimes if you click away it changes the name, sometimes it does not. What I am doing now is a "blind" renaming, ignoring the wrong display than save and re-open the file (some names appear correct after this) and continue with names which were not renamed..... When I have some file which I can publish here, where this behavior occurs, I will post...