Inkscape.org
Beyond the Basics export layers as svg files
  1. #1
    _michael_ _michael_ @_michael_

    Hi,

    is there an easy and fast way to export layers as svg-files in inkscape?

    An Example to make clear what I mean: I have a file with many layers. The names of these layers are "a", "b", "c", "d", ...

    I'd like to have multiple files:

    - a.svg: should only contain layer "a"

    - b.svg: should only contain layer "b"

    - ...

    Thanks

    Michael

  2. #2
    Tyler Durden Tyler Durden @TylerDurden
    *

    Somebody cobbled together this extension from a python script at github. The extension works in 1.0 and earlier, with caveats:

    • In 1.0, it will display an error after successfully running.
    • In 0.9xx versions, it will close the file after successfully running.
    • The output files will be found in the user extensions directory.

    Put the extension files in the user profile extensions directory, so they will not be clobbered when updating Inkscape.

    Use at your own risk.
    YMMV

    Stay 6' away from others.

  3. #3
    _michael_ _michael_ @_michael_

    Thanks, exactly what I've been looking for! I don't like the output directory. Because of this, I run it directly from the command line.

  4. #4
    oblio oblio @oblio

    Tyler - I have the same question except I want to export each layer as an independent .png (so I can use ImageMagick to make an animated .gif from it). 

    About 5 years ago I used to do this by installing JessyInk in the InkScape .svg file then Selecting File>Save a copy>JessyInk zipped pdf or png output>png as described in this (old) InkscapeWiki article: https://wiki.inkscape.org/wiki/index.php/Animation-(Layers) .  Since installing Inkscape 92.1 (4 years ago?) I have not been able to do the JessyInk Method including yesterday after I installed 92.5.  Here is the error message I got (in 92.3 and 92.5)after clicking Save; followed by a dialog that said " File C:\....zip could not be saved": (see Win7...Msg.png attached).

    I tried the export dialog tool in 92.5 checking the box for 'exporting groups' but this does not work because everything in the bounding box of each object (all are selected) shows up in the .png image.  I tried checking the 'hide all but selected' box but that only works when one object is selected - so that is not much better than individually exporting each layer. One of the exported .pngs is attached (see path1096.png). (I had Extensions>...>Interpolate> a triangle to a flat line then placed each object on its' own layer)

    I looked at: Book of Inkscape-The Definitive Guide to the Free Graphics Editor by Dmitry Kirsanov; especially chap20 (creating an animation) and appndx C (The Command Line)  but I don't know how to write a script in Python. I have tried scripts found on GitHub since I installed 92.1 but everything I found was older than 92.1 and either did not work at all or exported each object on all layers as separate objects.

    Then I saw _michael_'s post this morning and thought the command line and script might be the answer.  Your answer seemed to confirm that, but again I wanted to export .png's and I can't write a script.  Would it be as simple as substituting '.png' for '.svg' in your extension (in "write(listoflayers[counter]+'.svg')?  What about directing the output (files) to another directory using a full path?

    The extension you wrote appears to do with .svgs what I want to do with .pngs.  Could you help me 'cobble together' the right code to do that?

    Also, if I'm missing something about how to use either the group export tool or use JessyInk to achieve my goal I'm always willing to learn.

    Thanks a million,

    Bruce

     

     

     

    Path1096
    Win7Savcopyerrmsg
  5. #5
    Tyler Durden Tyler Durden @TylerDurden

    I remember tinkering with it, but I'm not sure I actually put it into an extension, or if somebody else did. I really can't code.

     

    Maybe you have seen this one: (?)
    https://github.com/jespino/inkscape-export-layers

  6. #6
    oblio oblio @oblio

    I tried to use the export-layers extension a couple years ago and was unable to get any exports.  That was in Inkscape 92.1.  I tried it today in 92.5 and could not get output other than the Inkscape error message (attached).  I put the .inx and .py files in ...AppData\Roaming\Inkscape\Extensions and on restarting Inkscape there was a new option under Extensions>Export: Export Layers.  Selecting that presents a dialog box (output path, jpeg/png, and dpi (default 90)). Click 'Apply' and the error message pops up.

    thanks ahead,

    Bruce

    Exprtlayerserrmsg
  7. #7
    Tyler Durden Tyler Durden @TylerDurden

    I'm not sure your system has the same extension. The one I have here is working in 0.92.2 and 0.92.5. It does not offer a choice of DPI.

    That aside, the error at the bottom of the provided image indicates a permissions problem. If you didn't specify a directory the where user has permissions, it will try to save on the root (like C:) and the system may block the write. Try saving to the desktop.

    System info? 

  8. #8
    Tyler Durden Tyler Durden @TylerDurden

    This is the export dialog on the one I have.

  9. #9
    oblio oblio @oblio

    I think it is the same extension since we both went to the same GitHub page (you gave the link to) but there may be a way for you and I to have different .inx and .py files.  I used the download button on GitHub then selected the 'zip' button.  A copy of the GitHub page and ReadMe are attached here as a .pdf. Here is the Export dialog box that shows up on my Win7 computer:

    I verified all folders in the export path have WRITE permission for both the SYSTEM and the Username groups (using R-click>properties>security tab)

    I tried both full absolute path names (C:\...) and relative (\Desktop).

    I tried both 'Select All in All Layers' and just opening the test file without selecting anything; before running the export-layers extension.

    I also tried turning on Windows Search service in case that had something to do with not being able to execute the export path.

    One curious outcome:  In one of my export attempts a new folder was created in my Username (Dad) folder.  It was named 'Users' and contained a 'Dad' subfolder which contained a 'Desktop' subfolder.  There was nothing in the 'Desktop' subfolder.  I believe this folder creation happened when I tried the export path of

    \Users\Dad\Desktop but I'm not very certain of that ( I did it in case Inkscape (exe in C:\Program Files.....) needed to go back up to the common node in the path name  in order to identify a valid export path name (where Desktop is in C:\Users\....). 

    I was not able to recreate the folder creation.

    In all cases I am getting the same error message from Inkscape (shown in post 6 above).  I'm also using Inkscape v.92.5 for all.

    Bottom line: I can't account for the difference between export dialog boxes but if they are different versions of the extension there might be a glitch in how Inkscape uses it to export the png files (unlikely?).  I agree with you about export/write permissions and can't help but think it is related to my export path typed in the dialog box or how it is being read by the extension. (the first time I ran the extension the dialog box 'Choose path-to-export' was pre-filled with '~/' w/o quotes.  I thought that was a Linux shorthand symbol and deleted and replaced it with a Windows absolute path.) 

    Do you know of any other System Info  or file structure checks to try? 

    Thanks again.

     

  10. #10
    Tyler Durden Tyler Durden @TylerDurden

    Yep, I'm using an older version of the extension. I'll attach the files I downloaded 3 yrs ago. You can scan it for bugs and try it if you like.

     

    Here is the exact string I used:

    C:\Users\tylerdurden\Documents\Inkscape\
    

    It will make a directory of the last element in the path, if one doesn't already exist, and place the files there. If it exists, it will place the files there.


    Feel free to share your test file, and I'll try that here.

     

    TD

  11. #11
    oblio oblio @oblio

    Tyler - works like a champ!  Thank you so much for staying with me on this.

    An error (possible) I was making was omitting the '\' (slash) at the end of the export path? - when I included it, when using the older .inx and .py files you provided, I could export my layers to any folder I wanted by using the absolute path name.  The newer files (I downloaded) still did not work - same error msg.

    I was varying the layer names and found that the extension only cares about the stacking order of the layers, not the name (except the bracketed 'fixed' or 'export').

    Also, the extension exports the page size listed in preferences. I got the smaller sized image by selecting the bkgnd image, then Edit>Set Page size to Selection, then clearing the selection and running the extension.

    I've attached the svg test file in case it helps clarify some of the comments made previously.

    What do you think about adding this as an Inkscape extension instead of leaving it in limbo for others to trip over in the future (seems like it comes up every year or two in the old forum).  Is there a way to post a written tutorial (sort of like a more detailed README)?  I'm willing to write it if it helps.  And last, is there a way for me to contact the extension developer through GitHub to advise of the non-working files that would be downloaded today?

    Thanks again, Bruce

     

     

    Intrptst
  12. #12
    _michael_ _michael_ @_michael_

    oblio wrote:

    > And last, is there a way for me to contact the extension developer through GitHub to advise of the non-working files that would be downloaded today?

    Yes it is, you can write an issue at github: https://github.com/jespino/inkscape-export-layers/issues

    But it looks as though the author (jesepino) ist not working on this project at the moment. But there has been a fork by dmitry-t 2 month ago: 

    https://github.com/jespino/inkscape-export-layers/issues/18

    https://github.com/dmitry-t/inkscape-export-layers

    Probably dmitry-t will fix your issue.

  13. #13
    oblio oblio @oblio

    Thanks for the dmitry-t fork URL

    I installed and ran the extension on my test file and it worked well (for PNG export).  Only difference I saw was that it numbers the layers from the top down (when the export dialog box for adding sequential number prefixes (001_layername.png, 002_...) is checked.

    Bruce

  14. #14
    dja001 dja001 @dja001
    😀

    Hi there,

    I had similar needs and found the links to the project by jespino reworked by dmitry-t and a bunch of others. I am by no means an Inkscape developer but I could get my own fork working without problems on Inkscape >1.

    I fixed a couple of bugs and added features I needed like pdf exports, easier specification of output directory, file prefixes, etc... 

    https://github.com/dja001/inkscape-export-layers

    Maybe some of the changes I made could be of help here?

  15. #15
    oblio oblio @oblio

    dja001      Thanks for your helpful input.  There have been several bug reports (on Gitlab) about this subject over the past year; one 'collection' - extension/issue/152 (Jessyink output error) appears to roll the functionality into the Inkscape native extension Jessyink  and another 'collection' - inbox/issue/2513 (export layers to png sequence) tries to solve this via the 3rd party extensions.  Possibly, the JessyInk solution will be in place in Inkscape version 1.1?  For previous versions (at least 92.x and  1.0) users will have to find the appropriate 3rd party extension for their operating system, like Tyler Durden and _michael_  have provided for Windows(?) above.

    I'm placing this comment so that people searching the forum for this subject can find a couple solutions and know that the developers are working on providing/restoring the functionality.