Page 1 of 1

SVG export with layers

Posted: Thu Apr 19, 2012 6:16 pm
by dave5
Is there a way of programmatically exporting to SVG and retaining layer data?

Re: SVG export with layers

Posted: Thu Apr 19, 2012 8:12 pm
by andrew
No, layer information is currently not transferred to SVG. The reason is that SVG does not have support for layers.

SVG has groups of course, but groups are a concept that is orthogonal to layers. For example a block in QCAD is exported as a group in SVG. Since two blocks may both contain entities on the same two different layers, the concept of groups alone is not sufficient to implement both layers and blocks but only either one of the two concepts.

Inkscape emulates layers somehow, but I didn't look into that yet. They extend SVG with several Inkscape specific tags and arguments. It's possible that QCAD will support that in the future which would of course mean that layers would be supported for Inkscape only.

Would that be useful for you? Can you give some information about your use case?

Re: SVG export with layers

Posted: Fri Apr 20, 2012 11:21 am
by hungerburg
I did a quick check with inkscape: when I group two objects, that are in different so called "layers", the group will then become part of the upper "layer". "layer" information of the objects themselves is lost by grouping them. This is an irreversible action. Exploding the group will put all the members into the "layer" of the group. This can be easily watched in the XML-Editor window of inkscape: "layers" are indeed groups with special attributs, but members do not reference these "layers" by special attributes at all.

As a consequence, as of Inkscape 0.48.2 r9819, there is NO way of transparently/reversibly mapping *two distinct hierarchies* like blocks and layers of QCAD+DXF to inkscape+SVG.

Re: SVG export with layers

Posted: Fri Apr 20, 2012 11:32 am
by andrew
hungerburg: thanks for the research. This is bad news. I have to admit that I've expected something different that could be supported.

In this case, the concept of layers in CAD is indeed not transferable to SVG / Inkscape.

Re: SVG export with layers

Posted: Fri Apr 20, 2012 12:12 pm
by hungerburg
Sorry for bringing bad news. I now read http://wiki.inkscape.org/wiki/index.php/DocumentLayers and there also is no indication that this is a known deficiency of inkscapes interpretation of what SVG can be taught to. Instead it says there, that Adobe Illustrator uses the same concepts, and the adobe online reference at least seems to point the same way (http://help.adobe.com/en_US/illustrator ... 635fa.html statement on transparency). If I find the time, I will look, if Illustrator can keep group and layer information separately and reversibly serialize as svg.

Re: SVG export with layers

Posted: Wed May 02, 2012 10:55 am
by hungerburg
I found the time to look at how Adobe Illustrator handles grouping and layering. It also has a tree view of the drawing's entities, similar to Inkscape's XML view. And just the same, groups are nodes below layers. Grouping of entities on different layers will put the group into one layer. Exploding this group later will put the members in this layer. So I did not bother to look how layers are serialized in SVG, because already the in-memory model seems not ready to support the DXF paradigm of two separate trees for groups and layers.

Re: SVG export with layers

Posted: Wed May 02, 2012 10:58 am
by andrew
OK, thanks for sharing this information.

Re: SVG export with layers

Posted: Tue May 08, 2012 1:58 am
by dave5
No stress... my use case was to use named layers to drive other business processes.