SVG export with layers

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
dave5
Newbie Member
Posts: 4
Joined: Thu Apr 19, 2012 6:15 pm

SVG export with layers

Post by dave5 » Thu Apr 19, 2012 6:16 pm

Is there a way of programmatically exporting to SVG and retaining layer data?

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: SVG export with layers

Post by andrew » Thu Apr 19, 2012 8:12 pm

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?

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Re: SVG export with layers

Post by hungerburg » Fri Apr 20, 2012 11:21 am

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.

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: SVG export with layers

Post by andrew » Fri Apr 20, 2012 11:32 am

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.

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Re: SVG export with layers

Post by hungerburg » Fri Apr 20, 2012 12:12 pm

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.

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Re: SVG export with layers

Post by hungerburg » Wed May 02, 2012 10:55 am

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.

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: SVG export with layers

Post by andrew » Wed May 02, 2012 10:58 am

OK, thanks for sharing this information.

dave5
Newbie Member
Posts: 4
Joined: Thu Apr 19, 2012 6:15 pm

Re: SVG export with layers

Post by dave5 » Tue May 08, 2012 1:58 am

No stress... my use case was to use named layers to drive other business processes.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”