From 6cbf749e78fdf59b5df0f52f2cb4f251308c9bd4 Mon Sep 17 00:00:00 2001 From: Marcus Nordstrom Date: Wed, 28 May 2025 21:45:38 +0200 Subject: [PATCH] feat: add svg to gcode parser --- .gitignore | 3 ++- config.toml | 12 ++++++++++++ requirements.txt | 1 + svg_to_gcode.py | 25 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 config.toml create mode 100755 svg_to_gcode.py diff --git a/.gitignore b/.gitignore index 908cd57..13252cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc .venv -*.bin \ No newline at end of file +*.bin +*.gcode \ No newline at end of file diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..5e68bd2 --- /dev/null +++ b/config.toml @@ -0,0 +1,12 @@ +[gwrite.hp7044b] +unit = "mm" +document_start = "(document_start)\n" +layer_start = "(Start Layer)\n" +line_start = "(Start Block)\n" +segment_first = """G00 Z5 +G00 X{x:.4f}f Y{y:.4f} Z1 +""" +segment = """G01 X{x:.4f} Y{y:.4f} Z-1\n""" +line_end = """G00 Z 5.0000\n""" +document_end = """G00 X0.0000 Y0.0000""" +invert_y = true \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9f5f49c..c254cc9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ vsketch vpype-perspective +vpype-gcode PyQT5 \ No newline at end of file diff --git a/svg_to_gcode.py b/svg_to_gcode.py new file mode 100755 index 0000000..e8d1dcf --- /dev/null +++ b/svg_to_gcode.py @@ -0,0 +1,25 @@ +#! /usr/bin/env python3 + +import argparse +import shlex +import vpype +import vpype_cli + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Convert SVG files to G-code.") + parser.add_argument("input", type=str, help="Input SVG file path") + parser.add_argument("output", type=str, help="Output G-code file path") + vpype_args = parser.parse_args() + + svg_collection, width, height = vpype.read_svg(vpype_args.input, 4) + doc = vpype.Document(svg_collection, page_size=(width, height)) + + @vpype_cli.cli.command(group="vsketch") + @vpype_cli.global_processor + def vsketchinput(document): + document.extend(doc) + return document + + vpype_args = "vsketchinput gwrite -p hp7044b {}".format(vpype_args.output) + vpype.config_manager.load_config_file("config.toml") + vpype_cli.cli.main(prog_name="vpype", args=shlex.split(vpype_args), standalone_mode=False) \ No newline at end of file