Layer support in SVG Export

Hi @stevebaer ,
Do you have plans for exporting layers, either via SVG or PDF? I think this is a must feature for working with complex files in an external graphic application as Affinity Designer. Currently, Affinity doesn’t have any advance selection tools as select by colour, select same fill or stroke… So exporting a complex drawing without layers it’s not a solution.

1 Like

I’m still trying to figure out the best approach for this. It seems like object names may actually be better than layers for working between Rhino and Affinity.

Thanks Steve. Why do you think objects’ name will work better than layers? I barely give any name to my objects.

I’m not sure if one way will work better than the other. Using a layer name will give a whole bunch of objects the same name in Affinity Designer.

Consider the case where you have two spheres on Layer 1. Each sphere will export as multiple curves in SVG. Using the layer name will make it so you can’t tell if a curve came from the first sphere or the second sphere. If we used the object name instead, then you could tell.

Most likely, we need to make it an option so you can pick which way you want to export based on your own personal workflow.

I wote for Layer name + number. I don’t know if it is enough to use 6 digits in case somebody stores more than 99 999 objects on a layer, or if one should use a four letter based coding for the number. AAAA-ZZZZ = 456K versions. And if you toss in A-Z+0-9 for each four you get 1.679 K versions.

Another option is to use SVG groups and name each group by the layer name.
This looks like it may be the best for getting structured information into Affinity Designer.

Here’s a sample I hacked together to give an idea of how it would be set up

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "">
<svg width="100%" height="100%" viewBox="0 0 2550 3300" version="1.1" xmlns="" xmlns:xlink="" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
    <g id="Layer-2">
        <path d="M268.294,1396.64C657.316,1845.03 837.166,2036.12 1307.14,1962.35C1777.12,1888.58 1943.75,1792.38 1976.3,1605.66" style="fill:none;stroke:rgb(0,255,20);stroke-width:28px;"/>
    <g id="Layer-1::Sublayer-X">
        <rect id="Object-1" x="693.323" y="590.356" width="602.628" height="587.434" style="fill:rgb(217,28,28);"/>
        <ellipse id="Object-2" cx="1437.77" cy="1146.01" rx="422.391" ry="267.575" style="fill:rgb(0,15,255);"/>
        <ellipse id="Object-3" cx="1351.66" cy="869.292" rx="406.837" ry="402.016" style="fill:rgb(217,28,28);"/>

I thought It would be possible to maintain layer information from Rhino to Affinity via .svg. Today I’ve created a drawing containing layers in InkScape and saved it as .SVG. I was able to open it in Affinity Designer with the same layer structure.

Having said that. Exporting layers as groups could work very well.

Is that was Inkscape does? Do you have a simple inkscape export that opens well in Affinity that I can see?

I just did a very simple one. It was created in Inkscape and it contains 2 layers. It opens in Affinity as expected.

Thanks; they’re using the SVG group tag to define layers. That seems to be the way to go.


Perfect! Thanks

I also used group in my SVG exporter, the only drawback is that drawing order is inverted between SVG group and rhino layer

1 Like

Did you nest groups when you encountered nested layers? If so, did that work in any other program?

Hi Steve,

Hope this info is useful somehow… Illustrator has nested layers. When saving as PDF there is an option to show the top level layers in the PDF file. If I open the PDF with Illustrator again the nested layers are still there. This would be nice to have.

And the PDF file… and how it looks in Acrobat with layers
IlluPdf.pdf (62.7 KB)

Hi Jess,
Layer support is on the wishlist for PDF; it is a different beast than SVG.

Sure, I was just playing with that stuff and thought I’ll share some stuff. Discourse didn’t like the SVG version of that file. So here attached as zip… (3.6 KB)

I am not sure to understand. If nested layer are layers as tree, yes I did implement that in the same way as Rhino, I used Layer.sortIndex to calculate the level of the layer, 0 for the root(s) … SVGsave.cs (64.6 KB)
In the source go to line 750, there is :
//Sort the layer using sortIndex
SortedDictionary<int, int> sortDictionaryLayer = new SortedDictionary<int, int>();
for (int i = 0; i < doc.Layers.Count; i++)
sortDictionaryLayer.Add(doc.Layers[i].SortIndex, i);

        //Max layer calculation in order to be able to change order of rendering
        int layer_level = 0;
        int max_level = 0;
        for (int k = 0; k < sortDictionaryLayer.Count; k++)
            layer_level = 0;
            foreach (char c in doc.Layers[sortDictionaryLayer[k]].FullPath)
                if (c == ':') layer_level++;
            layer_level /= 2;
            if (layer_level > max_level) max_level = layer_level;

Here an example in Rhino, and my viewer
In Opera and Inkscape
and the source

I was wondering if by doing this you found that Affinity Designer or Inkscape paid attention to the nesting more than one level deep. I tried creating groups that were nested multiple levels deep and Affinity designer didn’t appear to create nested layers of unlimited depth

I don’t know, I did the SVG exporter for Laser cutting, groups are useful for cutting or engraving. On Grasshopper forum Nik Willmore also made an implementation with nested layer and he found it useful for Illustrator.