summaryrefslogtreecommitdiff
path: root/support/dxf_export/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'support/dxf_export/__main__.py')
-rw-r--r--support/dxf_export/__main__.py60
1 files changed, 40 insertions, 20 deletions
diff --git a/support/dxf_export/__main__.py b/support/dxf_export/__main__.py
index 22af532..ff2a38f 100644
--- a/support/dxf_export/__main__.py
+++ b/support/dxf_export/__main__.py
@@ -3,20 +3,38 @@ from lib import util
from . import effect
-def _export_dxf(in_path, out_path):
- dxf_export = effect.DXFExportEffect()
+def _export_dxf(in_path, out_path, layers):
+ dxf_export = effect.DXFExportEffect(layers)
dxf_export.affect(args = [in_path], output = False)
with open(out_path, 'w') as file:
dxf_export.write(file)
-def _get_inkscape_layer_count(svg_path):
+def _get_inkscape_layers(svg_path):
document = xml.etree.ElementTree.parse(svg_path)
- layers = document.findall(
- '{http://www.w3.org/2000/svg}g[@{http://www.inkscape.org/namespaces/inkscape}groupmode="layer"]')
- return len(layers)
+ def iter_layers():
+ nodes = document.findall(
+ '{http://www.w3.org/2000/svg}g[@{http://www.inkscape.org/namespaces/inkscape}groupmode="layer"]')
+
+ for i in nodes:
+ inkscape_name = i.get('{http://www.inkscape.org/namespaces/inkscape}label').strip()
+
+ if inkscape_name.endswith(']'):
+ dxf_name, args = inkscape_name[:-1].rsplit('[', 1)
+
+ dxf_name = dxf_name.strip()
+ args = args.strip()
+
+ use_paths = 'p' in args
+ else:
+ use_paths = False
+ dxf_name = inkscape_name
+
+ yield effect.Layer(inkscape_name, dxf_name, use_paths = use_paths)
+
+ return list(iter_layers())
def _inkscape(svg_path, verbs):
@@ -32,40 +50,41 @@ def _inkscape(svg_path, verbs):
util.command(list(iter_args()))
-def _unfuck_svg_document(temp_svg_path):
+def _unfuck_svg_document(temp_svg_path, layers):
"""
- Unfucks an SVG document so is can be processed by the better_dxf_export plugin.
+ Unfucks an SVG document so is can be processed by the better_dxf_export plugin (or what's left of it).
"""
- layers_count = _get_inkscape_layer_count(temp_svg_path)
-
def iter_inkscape_verbs():
yield 'LayerUnlockAll'
yield 'LayerShowAll'
# Go to the first layer.
- for _ in range(layers_count):
+ for _ in layers:
yield 'LayerPrev'
# Copy each layer and flatten it to a single path object.
- for _ in range(layers_count):
+ for i in layers:
yield 'LayerDuplicate'
yield 'EditSelectAll'
yield 'ObjectToPath'
yield 'EditSelectAll'
yield 'SelectionUnGroup'
- yield 'EditSelectAll'
- yield 'StrokeToPath'
- yield 'EditSelectAll'
- yield 'SelectionUnion'
+
+ if not i.use_paths:
+ yield 'EditSelectAll'
+ yield 'StrokeToPath'
+ yield 'EditSelectAll'
+ yield 'SelectionUnion'
+
yield 'LayerNext'
# Go to the first layer again.
- for _ in range(2 * layers_count):
+ for _ in range(2 * len(layers)):
yield 'LayerPrev'
# Move the flattened shapes to the original layers.
- for _ in range(layers_count):
+ for _ in layers:
yield 'EditSelectAll'
yield 'EditDelete'
yield 'LayerNext'
@@ -88,9 +107,10 @@ def main(in_path, out_path):
shutil.copyfile(in_path, temp_svg_path)
- _unfuck_svg_document(temp_svg_path)
+ layers = _get_inkscape_layers(temp_svg_path)
+ _unfuck_svg_document(temp_svg_path, layers)
- _export_dxf(temp_svg_path, out_path)
+ _export_dxf(temp_svg_path, out_path, layers)
try: