Files
2026-11-06 08:12:29 +01:00

59 lines
2.9 KiB
Markdown

## SVG to Gcode converter for GRBL pen plotter
Forked from [vishpat/svg2gcode](https://github.com/vishpat/svg2gcode)
I found that the plugins for inkscape and illustrator would crash when I tried to convert SVG's with many thousands of lines to gcode.
So I modified this to generate gcode for GRBL based pen plotter
**Usage as cli:**
>python convert.py source.svg destination.gcode
**or in bash**
copy 's2g' to your path and run from anywhere
>s2g source.svg target.gcode
**Convert all SVG files in `artwork/`**
Run `make` from the repository root. Each `artwork/name.svg` is converted to
`gcode/name.gcode`. Only files that are newer than their corresponding output
are converted; changes to `config.py` or `svg2gcode.py` also rebuild all generated G-code. The
directories and Python command can be overridden, for example:
`make ARTWORK_DIR=my-art GCODE_DIR=out PYTHON=python3`.
**There is a brute force path optimisator algorithm. Very slow for large files, can be disabled in config.py**
Travel-distance measurements preserve all drawing shapes. Single-shape drawings
have zero inter-shape travel; SVGs with no drawable shapes are rejected.
Conversion raises Python's recursion limit to at least 100,000 as a temporary
workaround for long SVG paths. Larger paths may still exceed this limit, and
deep recursion can exhaust the stack on some Python versions and platforms.
**Illustrator exports in points, not mm** regardless of your document settings.
If units are set to points in the config file, we convert to mm on the fly.
With `auto_scale = True` (the default), drawings outside
`0 <= X <= bed_max_x` or `0 <= Y <= bed_max_y` are automatically fitted using
their actual coordinate bounds after unit conversion and SVG transformations.
Fitting preserves aspect ratio, never enlarges drawings, and shifts fitted
drawings to start at X0/Y0. Drawings already in range remain unchanged.
Set `auto_scale = False` to reject out-of-range drawings instead. The error
reports the offending coordinate and bed limits; no output is created or
overwritten on a size-check failure.
These are work-coordinate limits, not a check of controller offsets or Z travel.
There are various settings you can change in config.py. Most notably, you must set an upper and lower position for the z axis.
The `preamble` is emitted after the header and before the feed rate and drawing
moves. It currently homes with `$H`, selects millimeters, absolute positioning
and G54, then resets only the G54 Z offset to zero. X/Y offsets are preserved.
The controller or sender must support `$H` within a job. Regenerate existing
G-code with `make` and upload the new files to apply this startup sequence.
* zTravel is the height it will move to before traveling to the next stroke
* zDraw should be the height at which the pen will make contact with the paper
* zDraw should be the height at which the pen will make contact with the paper