diff options
author | jaseg <git@jaseg.net> | 2019-09-26 19:45:54 +0200 |
---|---|---|
committer | jaseg <git@jaseg.net> | 2019-09-26 19:45:54 +0200 |
commit | b2eb56076d47af08a11e10fa53446a00b849a13c (patch) | |
tree | 4537c06e2e9bc5b78a731231e6c049c8cd5f376c /support/inkscape_exporter.py | |
parent | 82b88f920a85487372cc6e0b46633e4aa328eb69 (diff) | |
download | pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.tar.gz pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.tar.bz2 pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.zip |
Pogojig mostly done: KiCAD export works
Diffstat (limited to 'support/inkscape_exporter.py')
-rwxr-xr-x | support/inkscape_exporter.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/support/inkscape_exporter.py b/support/inkscape_exporter.py new file mode 100755 index 0000000..4e80c63 --- /dev/null +++ b/support/inkscape_exporter.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import os +import shutil +import tempfile + +from pogojig.inkscape import effect, inkscape + + +def _unfuck_svg_document(temp_svg_path): + """ + Unfucks an SVG document so is can be processed by the better_dxf_export + plugin (or what's left of it). + """ + command_line = inkscape.InkscapeCommandLine(temp_svg_path) + layers = command_line.layers + + command_line.apply_to_document('LayerUnlockAll', 'LayerShowAll') + + layer_copies = [] + + for i in layers: + layer_copy = command_line.duplicate_layer(i) + layer_copies.append(layer_copy) + + command_line.apply_to_layer_content(layer_copy, 'ObjectToPath') + command_line.apply_to_layer_content(layer_copy, 'SelectionUnGroup') + + if not i.use_paths: + command_line.apply_to_layer_content(layer_copy, 'StrokeToPath') + command_line.apply_to_layer_content(layer_copy, 'SelectionUnion') + + for original, copy in zip(layers, layer_copies): + command_line.clear_layer(original) + command_line.move_content(copy, original) + command_line.delete_layer(copy) + + command_line.apply_to_document('FileSave', 'FileClose', 'FileQuit') + command_line.run() + + +if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('infile', metavar='input.svg', help='Inkscape SVG input file') + parser.add_argument('outfile', metavar='output.dxf', help='DXF output file') + args = parser.parse_args() + + effect.ExportEffect.check_document_units(args.infile) + + with tempfile.TemporaryDirectory() as tmpdir: + temp_svg_path = os.path.join(tmpdir, os.path.basename(args.infile)) + shutil.copyfile(args.infile, temp_svg_path) + + _unfuck_svg_document(temp_svg_path) + + export_effect = effect.ExportEffect() + export_effect.affect(args=[temp_svg_path], output=False) + + with open(args.outfile, 'w') as f: + export_effect.write_dxf(f) |