1

I have one SVG created in Inkscape. It has a layer* containing rectangles which define clipping boundaries. It has multiple other layers containing the elements that I want to end up rendered into images. The output that I'm looking for is one image (probably png) for each combination of (a clipping rectangle in the first layer) * (a layer other than the first). The contents of that image will be equivalent to using Export Selection in Inkscape, with the clipping rectangle selected and the other layer being the only visible layer. The name of the image will be some combination of identifying information (id, title, label, etc) from the rectangle and the other layer.

How can I automate this? Doing it manually through Inkscape's Export interface is getting more time consuming each time I add a layer or a new clipping rectangle..

* I believe a Layer in Inkscape is implemented in SVG as a group.

3
  • Hi. Wouldn't it be better to put each graphic (or combination) on its own page? Name the pages as you desire. Then there would be no need for clipping rectangles or layers. Then you could use Inkscapes Batch Export, set to Pages. It's also possible to do the same with Batch Export set to Selection, and use group names instead of page names. To be honest, there's no way to automate this in Inkscape that will do it the way you describe, at least not without coding of some kind.
    – Billy Kerr
    Commented Oct 30, 2023 at 23:58
  • see an example using the Batch Export for pages
    – Billy Kerr
    Commented Oct 31, 2023 at 0:06
  • @BillyKerr I did try moving from the layer of clipping rectangles to pages. Batch Export Pages is half of what I need. Batch Export Layers is half of what I need. But there's no Batch Export Pages+Layers. I did end up scripting a solution.
    – Sparr
    Commented Nov 2, 2023 at 16:41

1 Answer 1

1

Here's what I came up with as a bash script using inkscape command line actions:

for layer in "ids" "of" "the" "content" "layers"; do
    for entity in "ids" "of" "the" "clipping" "rectangles"; do
        inkscape input.svg \
            --actions="select-all:layers; object-set-attribute:style, display:none; select-clear;
                       select-by-id:${layer}; object-set-attribute:style, display:inline;
                       export-filename:${layer}-${entity}.png; export-id:${entity}; export-do;
                      "
    done
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.