Inkscape layers are SVN groups. You save save an SVG file and open it in a text editor, or use the XML Editor within Inkscape Ctrl+Shift+X. A typical (abbreviated) SVG from Inkscape will look like this:
<svg:svg id="svg2">
<svg:defs id="defs4">
<svg:metadata>
[...]
</svg:metadata>
<svg:g id="layer1" inkscape:groupmode="layer" inkscape:label="My Layer 1">
<svg:path [...] />
</svg:g>
<svg:g id="layer2" inkscape:groupmode="layer" inkscape:label="My Layer 2">
[...]
</svg:g>
</svg:svg>
From this, you can see that:
- Layers are just groups
- Inkscape using a special attribute
inkscape:groupmode
to differentiate groups that are "layers"
- The name you give a layer is in the
inkscape:label
attribute
- If you want to select all layer in an Inkscape SVG, you want
//svg:g[@inkscape:groupmode='layer']
(see gotcha below)
How you extract and use this information will depend on the scripting language.
Gotcha: Inkscape does allow nested layers, but it doesn't look like you can do that in the UI, so most users won't do it. Nesting layers can be done by manually adding the the groupmode
attribute to a group. If you only want top-level layers, be sure to explicitly ask for them, such as /svg:svg/svg:g[@inkscape:groupmode='layer']
.