summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github@lexneva.name>2016-11-02 23:17:36 -0400
committerLex Neva <github@lexneva.name>2016-11-02 23:20:31 -0400
commit980539864401ed05cd9b39450d8634e26192408b (patch)
tree78d0724de6a42d6b3fc285913c81987ad84269c8
parent841e9196ba27176d606d448d30f6c2b6b6bbc739 (diff)
add embroider_update extension to convert old-style param names to new
-rw-r--r--embroider_update.inx16
-rw-r--r--embroider_update.py46
2 files changed, 62 insertions, 0 deletions
diff --git a/embroider_update.inx b/embroider_update.inx
new file mode 100644
index 00000000..b700e605
--- /dev/null
+++ b/embroider_update.inx
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+ <_name>Update embroidery param names</_name>
+ <id>lexelby.embroider.update</id>
+ <dependency type="executable" location="extensions">embroider_update.py</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+ <effect>
+ <object-type>all</object-type>
+ <effects-menu>
+ <submenu _name="Embroidery"/>
+ </effects-menu>
+ </effect>
+ <script>
+ <command reldir="extensions" interpreter="python">embroider_update.py</command>
+ </script>
+</inkscape-extension>
diff --git a/embroider_update.py b/embroider_update.py
new file mode 100644
index 00000000..5597cdcc
--- /dev/null
+++ b/embroider_update.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+#
+# Update embroidery parameters stored in XML attributes from old to new
+# format.
+
+import sys
+sys.path.append("/usr/share/inkscape/extensions")
+import os
+import inkex
+
+PIXELS_PER_MM = 10
+
+class EmbroiderParams(inkex.Effect):
+ def __init__(self, *args, **kwargs):
+ inkex.Effect.__init__(self)
+
+ self.mapping = { "zigzag_spacing": "zigzag_spacing_mm",
+ "row_spacing": "row_spacing_mm",
+ "pull_compensation": "pull_compensation_mm",
+ "max_stitch_length": "max_stitch_length_mm",
+ "satin_underlay": "contour_underlay",
+ "satin_underlay_inset": "contour_underlay_inset_mm",
+ "satin_zigzag_underlay_spacing": "zigzag_underlay_spacing_mm",
+ "satin_center_walk": "center_walk_underlay",
+ "stitch_length": "running_stitch_length_mm",
+ }
+
+ def effect(self):
+ for node in self.document.getroot().iter():
+ for old, new in self.mapping.iteritems():
+ old = "embroider_%s" % old
+ new = "embroider_%s" % new
+
+ value = node.attrib.pop(old, None)
+ if value:
+ if new.endswith('_mm') and value.strip():
+ value = str(float(value) / PIXELS_PER_MM)
+
+ node.set(new, value)
+
+ if 'embroider_zigzag_underlay_spacing_mm' in node.attrib:
+ node.set('embroider_zigzag_underlay', 'yes')
+
+if __name__ == '__main__':
+ e = EmbroiderParams()
+ e.affect()