Inkscape Extension

This extension adds support for layers in inkscape. A layer in inkscape is an extended group container with additional label and locked attributes. Inkscape supports nested layers.

First import the inkscape extension:

import svgwrite
from svgwrite.extensions import Inkscape

dwg = svgwrite.Drawing('test-inkscape-extension.svg', profile='full', size=(640, 480))

You have to activate the extension for each drawing, because additional XML name spaces are required:

inkscape = Inkscape(dwg)

Create a new layer, all attributes that are supported by the group container are also allowed:

top_layer = inkscape.layer(label="Top LAYER 1", locked=True)

Add new layer as top level layer to the SVG drawing:


Create new elements and add them to a layer:

line = dwg.line((100, 100), (300, 100), stroke=svgwrite.rgb(10, 10, 16, '%'), stroke_width=10)

text = dwg.text('Test', insert=(100, 100), font_size=100, fill='red')

Create another layer and add them as nested layer to “Top LAYER 1”:

nested_layer = inkscape.layer(label="Nested LAYER 2", locked=False)

text = dwg.text('Test2', insert=(100, 200), font_size=100, fill='blue')