diff --git a/gerbolyze/gerbolyze.py b/gerbolyze/gerbolyze.py
index f77e047..d4b4ab5 100755
--- a/gerbolyze/gerbolyze.py
+++ b/gerbolyze/gerbolyze.py
@@ -504,7 +504,7 @@ DEFAULT_EXTRA_LAYERS = [ layer for layer in LAYER_RENDER_ORDER if layer != "dril
def template_layer(name):
return f''
-def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS):
+def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'):
(x1, x2), (y1, y2) = bounds
w_mm, h_mm = (x2 - x1), (y2 - y1)
@@ -519,6 +519,7 @@ def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS):
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
width="{w_mm}mm" height="{h_mm}mm" viewBox="0 0 {w_mm} {h_mm}" >
+
@@ -538,7 +539,7 @@ def svg_pt_to_mm(pt_len, dpi=CAIRO_SVG_HARDCODED_DPI):
return f'{float(pt_len) / dpi * MM_PER_INCH}mm'
-def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS):
+def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'):
svg = etree.fromstring(svg_data)
# add inkscape namespaces
@@ -555,6 +556,11 @@ def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS
svg.set('width', svg_pt_to_mm(svg.get('width')))
svg.set('height', svg_pt_to_mm(svg.get('height')))
+ # add inkscape elem to set currently selected layer
+ namedview_elem = etree.SubElement(svg, SODIPODI_NS+'namedview')
+ namedview_elem.set('id', "namedview23")
+ namedview_elem.set(INKSCAPE_NS+'current-layer', f'g-{current_layer}')
+
# make original group an inkscape layer
orig_g = svg.find(SVG_NS+'g')
orig_g.set('id', 'g-preview')