svg2gcode 3.2.7__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/PKG-INFO +97 -44
  2. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/README.md +96 -43
  3. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/__init__.py +1 -1
  4. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/__main__.py +49 -2
  5. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/__init__.py +4 -2
  6. svg2gcode-3.2.7/svg2gcode/svg_to_gcode/compiler/_compiler_1.py → svg2gcode-3.3.0/svg2gcode/svg_to_gcode/compiler/_compiler.py +253 -98
  7. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/css_color.py +8 -2
  8. svg2gcode-3.2.7/svg2gcode/svg_to_gcode/compiler/_compiler.py +0 -941
  9. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/LICENSE +0 -0
  10. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/pyproject.toml +0 -0
  11. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/LICENSE +0 -0
  12. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
  13. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
  14. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
  15. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
  16. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
  17. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/formulas.py +0 -0
  18. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
  19. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
  20. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
  21. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
  22. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
  23. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
  24. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
  25. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
  26. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
  27. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
  28. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
  29. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
  30. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
  31. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +0 -0
  32. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +0 -0
  33. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
  34. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
  35. {svg2gcode-3.2.7 → svg2gcode-3.3.0}/svg2gcode/svg_to_gcode/svg_parser/debug_methods.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: svg2gcode
3
- Version: 3.2.7
3
+ Version: 3.3.0
4
4
  Summary: svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
5
5
  Keywords: scalable vector graphics,svg,image,laser cutter,laser engraving
6
6
  Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
@@ -14,46 +14,97 @@ Project-URL: Home, https://github.com/johannesnoordanus/svg2gcode
14
14
 
15
15
  # svg2gcode
16
16
 
17
- A commandline steering program that enables laser cutting of svg drawings```<svg:path ..>```tags and combined engraving of svg images```<svg:image ..>```tags.
18
- It is based on library *SvgToGcode* (*fork*: *https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
17
+ *svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*fork*: *https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
19
18
 
20
- Drawings and images can be composed using Inkscape (or other SVG image software) and saved to a *.svg* file. This file can then be converted to gcode by *svg2gcode*.
21
- Gcode produced in this way has the advantage that drawings and images have the same - relative - position and orientation as can be seen on the composer window.
22
- This makes combined cutting and engraving as easy as orientating the (wood) slab once.
19
+ Drawings and images can be composed using Inkscape (or other *SVG* image software), saved to a *.svg* file and - *WYSIWYG* - converted to gcode.
20
+ Color coding can be used to mark what part(s) of the drawing to cut, engrave or even ignore.
23
21
 
24
- SVG *path* and *image* objects are supported. Note that other drawing object must be converted to a *path* to be able to translate them to a gcode sequence.
25
- Recently (version 3.0.0 and higher) support for *stroke* color and *stroke-width* attributes of SVG *path* objects is added.
26
- This means that it is possible to make laser engravings of text (fonts) and other drawing objects having a border with a specific color.
27
- It is even possible to use alpha channel for these drawing objects now.
22
+ Raster elements within a *SVG* drawing are converted pixel perfect, vector elements are drawn at the specified resolution.
23
+ Vector elements are converted including line width, fill and color, but note that colors (including alpha-channel) are converted to black and white.
24
+ (This is because laser engravings resemble black and white images.)
25
+ This means that it is possible to make laser engravings of text (fonts) and other drawing elements or even the entire vector drawing.
28
26
 
29
- Controlling laser power, pixel size and other settings can be done via commandline parameters (see below) or within Inkscape using the XMLeditor.
30
- Image attributes ```gcode_pixelsize```, ```gcode_maxpower```, ```gcode_speed```, ```gcode_noise```, ```gcode_speedmoves```, ```gcode_overscan``` and ```gcode_showoverscan``` can be set per object.
31
- (Image attributes can be added within the XMLeditor (Inkscape) by using the **+**).
32
- Note that image attributes override explicit or default commandline settings.
27
+ You have full control of placing (locating) of the gcode end result. You can for example translate, scale, rotate and have the origin at the image center.
28
+ *svg2gcode* produces highly optimised and accurate *gcode*. *gcode* file length is relatively short (because codes and coordinates are emitted sparsely) and laser drawing is sped up by speed moves and skipping of all empty parts.
33
29
 
34
- You have full control of placing (locating) of the result gcode via options *--origin*, <i>--rotate</i> and *--scale*.
35
- Option *--selfcenter* can be used to set the origin at the center of the image.
36
- Note that gcode file headers contain compile information like the boundingbox and boundingbox center coordinates.
30
+ More info can be obtained by looking at the documentation and examples below and the documentation of *image2gcode* (for example about calibration of laser engravers).
37
31
 
38
- Version 2.0.0 and higher have important speed optimizations. Engravings run significantly faster and skip from one image zone to the other at maximum speed.
39
- See options ```--speedmoves``` and ```--noise``` for example.
32
+ *svg2gcode* has three related programs: *image2gcode* mentioned above has similar capabilities but handles raster image files (like *png* and *jpg*) directly, *gcode2image* performs the inverse function and is capable of showing multiple writes (burns) to the same location and last *grblhud* which gives full control over gcode execution.
40
33
 
41
- Version 3.0.0 and higher have support for 'stroke' (color) and 'stroke-width' attributes, this means that cutting a path works a bit different now.
42
- When the *stroke* attribute of a *path* is nonexistent or set to none, the path will be laser burned with the value set by option *--cuttingpower*.
34
+ -----
43
35
 
44
- Version 3.1.0 and higher have support for 'fill' (color) and 'fill-rule' attributes. Currently only fill rule 'evenodd' is supported.
36
+ Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
45
37
 
46
- Also, *svg2gcode* option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the SVG.
47
- Option ```--nofill``` (not set by default) is added to disable path fills.
38
+ My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* below).
48
39
 
49
- More info can be obtained by looking at the examples below and from program *image2gcode* and its documentation (for example about callibrating laser engravers).
50
-
51
- Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
40
+ <sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
41
+ ### Supported SVG elements and attributes
52
42
 
53
- My next update will add fill-rule 'nonzero'.
43
+ *SVG* *path* and *image* elements (specific: ```<svg:path ..>```tags and images```<svg:image ..>```tags) are supported. Other drawing objects must be converted to a *path* first to be able to translate them to a gcode sequence.
54
44
 
45
+ Attributes *stroke* (color), *stroke-width*, *stroke_alpha*, *fill* (color), *fill-rule*, *fill_alpha* are supported.
46
+ Currently only value *evenodd* of *fill-rule* is supported.
55
47
 
56
- To summarize:
48
+ ### Important Commandline options
49
+
50
+ Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
51
+ For example:
52
+ ```
53
+ > svg2gcode --color_coded "black = ignore red = cut blue = engrave" paws.svg paws.gc
54
+ ```
55
+ As a consequence all 'black' path elements will be ignored and will not appear after conversion, all red paths will be cut and all blue paths will be engraved (having color blue).
56
+ The corresponding gcode file contains lines like below to indicated which 'black path' is skipped:
57
+ ```
58
+ ; svg2gcode 3.2.8 (2024-07-28 11:39:27)
59
+ ; arguments:
60
+ ; laser_power: 850,
61
+ ; movement_speed: 1000,
62
+ ...
63
+ ; image_showoverscan: False,
64
+ ; color_coded: black = ignore red = cut blue = engrave
65
+ ; Boundingbox: (X0.8,Y0.0:X5.1,Y4.3)
66
+ ; boundingbox center: (X2.951648,Y2.148172)
67
+ ; GRBL 1.1, unit=mm, absolute coordinates
68
+
69
+ ; Machine settings:
70
+ ; rapid movement,
71
+ ...
72
+ ; XY plane,
73
+ ; cutter compensation off,
74
+ ; coordinate system 1,
75
+ ; move 'unit'/min
76
+ G0 G17 G40 G54 G94
77
+
78
+ G21
79
+ G90
80
+ ; pass #1
81
+
82
+ ; --color_coded: ignore path 'path304-9-2-9-41-7', color '#000000'
83
+ ```
84
+ Note that it doesn't matter if a specific color action is set but no corresponding path exits.
85
+ Note that multiple collors can be set per 'action':
86
+ ```
87
+ > svg2gcode --color_coded "black = ignore red = cut green = ignore blue = engrave orange = engrave yellow = cut" paws.svg paws.gc
88
+ ```
89
+ Note that engraving is the default action, so if option *color_coded* isn't set or *color_coded* has no engrave color set, all paths having no other action set will be engraved (but see below).
90
+
91
+ This makes it possible to make a drawing where all path elements are drawn in their respective colors to make an engraving of the entire vector drawing.
92
+ When you set the engrave action for a set of colors, only those colors will be engraved (having their respective colors), all other paths having no action set are ignored.
93
+ Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is interpreted as a cut action.
94
+
95
+ Option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the *SVG*.
96
+ Note that this option cannot be set at the same time as *--color_coded* above.
97
+
98
+ Option ```--nofill``` makes it possible to disable all path fills.
99
+ Options ```--origin --rotate --scale --selfcenter``` can be used to locate and transform the gcode image.
100
+ Option ```--speedmoves``` makes it possible to run engravings significantly faster and skip from one image zone to the other at maximum speed.
101
+ Option ```--noise``` suppresses stray pixels
102
+
103
+ Controlling laser power, pixel size and other settings can be done via commandline parameters but also via the following attributes (which can be set within the *.svg* file directly or within Inkscape using the XMLeditor):
104
+ ```gcode_pixelsize```, ```gcode_maxpower```, ```gcode_speed```, ```gcode_noise```, ```gcode_speedmoves```, ```gcode_overscan``` and ```gcode_showoverscan``` can be set per vector element. (Image attributes can be added within the XMLeditor (Inkscape) by using the **+**).
105
+ Note that these attributes override explicit or default commandline settings.
106
+
107
+ ### gcode optimizations
57
108
 
58
109
  Optimized gcode
59
110
  - draw pixels in one go until change of power
@@ -62,18 +113,14 @@ Optimized gcode
62
113
  - does not emit zero power (or below cutoff) pixels
63
114
 
64
115
  General optimizations
65
- - laser head has defered and sparse moves.
116
+ - laser head has deferred and sparse moves.
66
117
  (XY locations are virtual, head does not always follow)
67
118
  - moves at high speed (G0) over 10mm (default) or more zero pixels
68
119
  - low burn levels (stray pixels) can be suppressed (default off)
69
- - option *--constantburn* selects constant burn mode *M3* (for cutting and engraving) instead of default dynamic burn mode *M4*
120
+ - default --constantburn mode *gcode M3*
70
121
  - borders are drawn in parallel and in one go, following the *path* coordinates.
71
122
  - fill has support for alpha channel and 'fill-opacity'
72
123
 
73
- **Tip**: use commandline program *grblhud* *(https://github.com/johannesnoordanus/grblhud)* to have full control over gcode execution,
74
- also, program *image2gcode* has similar capabilities but handles raster images files (like *png* and *jpg*) directly.
75
-
76
- **Tip2**: another program *LaserWeb* (not made by me) is quite capable and has an excelent 3D gcode visualizer, it is able to calculate 3D paths for CNC machines, including the bit diameter.
77
124
 
78
125
  ### Install:
79
126
  ```
@@ -86,14 +133,14 @@ Some linux distributions use a managed environment in which you cannot install p
86
133
  > pipx install svg2gcode
87
134
  ```
88
135
 
89
- <sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
90
136
  ### Usage:
91
137
  ```
92
138
  > svg2gcode --help
93
- usage: svg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
94
- [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>] [--noise <default:0>]
95
- [--overscan <default:0>] [--showoverscan] [--constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut]
96
- [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--fan] [-V]
139
+ usage: runsvg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
140
+ [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>]
141
+ [--noise <default:0>] [--overscan <default:0>] [--showoverscan] [--constantburn | --no-constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y]
142
+ [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan]
143
+ [-V]
97
144
  svg gcode
98
145
 
99
146
  Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.
@@ -127,7 +174,8 @@ options:
127
174
  --overscan <default:0>
128
175
  overscan image lines to avoid incorrect power levels for pixels at left and right borders, number in pixels, default off
129
176
  --showoverscan show overscan pixels (note that this is visible and part of the gcode emitted!)
130
- --constantburn set constant burn mode M3 (default set to dynamic burn mode M4); this enhances engraving quality
177
+ --constantburn, --no-constantburn
178
+ default constant burn mode (M3)
131
179
  --origin delta-x delta-y
132
180
  translate origin by vector (delta-x,delta-y) in mm (default not set, option --selfcenter cannot be used at the same time)
133
181
  --scale factor-x factor-y
@@ -140,6 +188,8 @@ options:
140
188
  machine x-axis lengh in mm
141
189
  --ymaxtravel <default:400>
142
190
  machine y-axis lengh in mm
191
+ --color_coded <default:"">
192
+ set action for path with specific stroke color "[color = [cut|engrave|ignore] *]*", example: --color_coded "black = ignore purple = cut blue = engrave"
143
193
  --fan set machine fan on
144
194
  -V, --version show version number and exit
145
195
  ```
@@ -151,8 +201,9 @@ You can also store svg2gcode settings in configuration file `~/.config/svg2gcode
151
201
  xmaxtravel= 400
152
202
  ymaxtravel= 400
153
203
  imagespeed = 6000
204
+ color_coded = "black = ignore purple = cut blue = engrave"
154
205
  ```
155
- It can be used with any parameter which takes a value, and alows to persist your laser settings.
206
+ It can be used with any parameter which takes a value, and allows to persist your laser settings.
156
207
  You can create this configuration file using an editor like vi or nano.
157
208
  An alternative (quick) way to do that is to enter:
158
209
  ```
@@ -160,6 +211,7 @@ $ mkdir ~/.config
160
211
  $ echo "xmaxtravel= 400
161
212
  ymaxtravel= 400
162
213
  imagespeed = 6000
214
+ color_coded = \"black = ignore purple = cut blue = engrave\"
163
215
  " > ~/.config/svg2gcode.toml
164
216
  ```
165
217
  (but use your own settings!)
@@ -251,7 +303,7 @@ or add 'gcode-pathcut' to the style string:
251
303
  ```
252
304
  (Note that this makes it possible to selectively cut path objects within the SVG.)
253
305
 
254
- or add *svg2gcode* option *--pathcut* to override all path stroke attributes within the SVG document
306
+ or add *svg2gcode* option *--pathcut* to override all path stroke attributes within the SVG document or use option *--color_coded* and set a cut action for the stroke color.
255
307
 
256
308
  Run *svg2gcode* (with same options) again.
257
309
  Now the gcode after conversion will look like this:
@@ -280,6 +332,7 @@ Don't worry if your lasercutter has no Z-axis, because this parameter will be ig
280
332
 
281
333
  If you have a CNC machine (which does have a Z-axis) you can mill in depth (so to speak), but you can also add - or switch to - a laser head and use the gcode to be able to really laser cut deeper!
282
334
 
335
+
283
336
  #### Create two types of gcode file
284
337
  One containing the drawings of the .svg, the other containing the images:
285
338
  ```
@@ -292,7 +345,7 @@ One containing the drawings of the .svg, the other containing the images:
292
345
 
293
346
  ### Burn mode M3/M4:
294
347
 
295
- Default *svg2gcode* uses dynamic burn mode *M4*. This can be changed by setting option *--constantburn* which selects burn mode *M3*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
348
+ Default *svg2gcode* uses constant burn mode *M3*. This can be changed by setting option *--no-constantburn* which selects burn mode *M4*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
296
349
 
297
350
  ### Notes:
298
351
  - drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
@@ -1,45 +1,96 @@
1
1
  # svg2gcode
2
2
 
3
- A commandline steering program that enables laser cutting of svg drawings```<svg:path ..>```tags and combined engraving of svg images```<svg:image ..>```tags.
4
- It is based on library *SvgToGcode* (*fork*: *https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
3
+ *svg2gcode* is a *WYSIWYG* converter of Scalable Vector Graphic *(SVG)* drawings. It is based on library *SvgToGcode* (*fork*: *https://github.com/johannesnoordanus/SvgToGcode*)<sup>(*)</sup>.
5
4
 
6
- Drawings and images can be composed using Inkscape (or other SVG image software) and saved to a *.svg* file. This file can then be converted to gcode by *svg2gcode*.
7
- Gcode produced in this way has the advantage that drawings and images have the same - relative - position and orientation as can be seen on the composer window.
8
- This makes combined cutting and engraving as easy as orientating the (wood) slab once.
5
+ Drawings and images can be composed using Inkscape (or other *SVG* image software), saved to a *.svg* file and - *WYSIWYG* - converted to gcode.
6
+ Color coding can be used to mark what part(s) of the drawing to cut, engrave or even ignore.
9
7
 
10
- SVG *path* and *image* objects are supported. Note that other drawing object must be converted to a *path* to be able to translate them to a gcode sequence.
11
- Recently (version 3.0.0 and higher) support for *stroke* color and *stroke-width* attributes of SVG *path* objects is added.
12
- This means that it is possible to make laser engravings of text (fonts) and other drawing objects having a border with a specific color.
13
- It is even possible to use alpha channel for these drawing objects now.
8
+ Raster elements within a *SVG* drawing are converted pixel perfect, vector elements are drawn at the specified resolution.
9
+ Vector elements are converted including line width, fill and color, but note that colors (including alpha-channel) are converted to black and white.
10
+ (This is because laser engravings resemble black and white images.)
11
+ This means that it is possible to make laser engravings of text (fonts) and other drawing elements or even the entire vector drawing.
14
12
 
15
- Controlling laser power, pixel size and other settings can be done via commandline parameters (see below) or within Inkscape using the XMLeditor.
16
- Image attributes ```gcode_pixelsize```, ```gcode_maxpower```, ```gcode_speed```, ```gcode_noise```, ```gcode_speedmoves```, ```gcode_overscan``` and ```gcode_showoverscan``` can be set per object.
17
- (Image attributes can be added within the XMLeditor (Inkscape) by using the **+**).
18
- Note that image attributes override explicit or default commandline settings.
13
+ You have full control of placing (locating) of the gcode end result. You can for example translate, scale, rotate and have the origin at the image center.
14
+ *svg2gcode* produces highly optimised and accurate *gcode*. *gcode* file length is relatively short (because codes and coordinates are emitted sparsely) and laser drawing is sped up by speed moves and skipping of all empty parts.
19
15
 
20
- You have full control of placing (locating) of the result gcode via options *--origin*, <i>--rotate</i> and *--scale*.
21
- Option *--selfcenter* can be used to set the origin at the center of the image.
22
- Note that gcode file headers contain compile information like the boundingbox and boundingbox center coordinates.
16
+ More info can be obtained by looking at the documentation and examples below and the documentation of *image2gcode* (for example about calibration of laser engravers).
23
17
 
24
- Version 2.0.0 and higher have important speed optimizations. Engravings run significantly faster and skip from one image zone to the other at maximum speed.
25
- See options ```--speedmoves``` and ```--noise``` for example.
18
+ *svg2gcode* has three related programs: *image2gcode* mentioned above has similar capabilities but handles raster image files (like *png* and *jpg*) directly, *gcode2image* performs the inverse function and is capable of showing multiple writes (burns) to the same location and last *grblhud* which gives full control over gcode execution.
26
19
 
27
- Version 3.0.0 and higher have support for 'stroke' (color) and 'stroke-width' attributes, this means that cutting a path works a bit different now.
28
- When the *stroke* attribute of a *path* is nonexistent or set to none, the path will be laser burned with the value set by option *--cuttingpower*.
20
+ -----
29
21
 
30
- Version 3.1.0 and higher have support for 'fill' (color) and 'fill-rule' attributes. Currently only fill rule 'evenodd' is supported.
22
+ Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
31
23
 
32
- Also, *svg2gcode* option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the SVG.
33
- Option ```--nofill``` (not set by default) is added to disable path fills.
24
+ My next update will add *fill-rule* 'nonzero' (see information on *fill-rule* below).
34
25
 
35
- More info can be obtained by looking at the examples below and from program *image2gcode* and its documentation (for example about callibrating laser engravers).
36
-
37
- Please consider supporting me, so I can make this application better and add new functionality to it: <http://paypal.me/johannesnoordanus/5,00>
26
+ <sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
27
+ ### Supported SVG elements and attributes
38
28
 
39
- My next update will add fill-rule 'nonzero'.
29
+ *SVG* *path* and *image* elements (specific: ```<svg:path ..>```tags and images```<svg:image ..>```tags) are supported. Other drawing objects must be converted to a *path* first to be able to translate them to a gcode sequence.
40
30
 
31
+ Attributes *stroke* (color), *stroke-width*, *stroke_alpha*, *fill* (color), *fill-rule*, *fill_alpha* are supported.
32
+ Currently only value *evenodd* of *fill-rule* is supported.
41
33
 
42
- To summarize:
34
+ ### Important Commandline options
35
+
36
+ Option ```--color_coded``` can be used to specify what part(s) of the drawing to cut, engrave or even ignore.
37
+ For example:
38
+ ```
39
+ > svg2gcode --color_coded "black = ignore red = cut blue = engrave" paws.svg paws.gc
40
+ ```
41
+ As a consequence all 'black' path elements will be ignored and will not appear after conversion, all red paths will be cut and all blue paths will be engraved (having color blue).
42
+ The corresponding gcode file contains lines like below to indicated which 'black path' is skipped:
43
+ ```
44
+ ; svg2gcode 3.2.8 (2024-07-28 11:39:27)
45
+ ; arguments:
46
+ ; laser_power: 850,
47
+ ; movement_speed: 1000,
48
+ ...
49
+ ; image_showoverscan: False,
50
+ ; color_coded: black = ignore red = cut blue = engrave
51
+ ; Boundingbox: (X0.8,Y0.0:X5.1,Y4.3)
52
+ ; boundingbox center: (X2.951648,Y2.148172)
53
+ ; GRBL 1.1, unit=mm, absolute coordinates
54
+
55
+ ; Machine settings:
56
+ ; rapid movement,
57
+ ...
58
+ ; XY plane,
59
+ ; cutter compensation off,
60
+ ; coordinate system 1,
61
+ ; move 'unit'/min
62
+ G0 G17 G40 G54 G94
63
+
64
+ G21
65
+ G90
66
+ ; pass #1
67
+
68
+ ; --color_coded: ignore path 'path304-9-2-9-41-7', color '#000000'
69
+ ```
70
+ Note that it doesn't matter if a specific color action is set but no corresponding path exits.
71
+ Note that multiple collors can be set per 'action':
72
+ ```
73
+ > svg2gcode --color_coded "black = ignore red = cut green = ignore blue = engrave orange = engrave yellow = cut" paws.svg paws.gc
74
+ ```
75
+ Note that engraving is the default action, so if option *color_coded* isn't set or *color_coded* has no engrave color set, all paths having no other action set will be engraved (but see below).
76
+
77
+ This makes it possible to make a drawing where all path elements are drawn in their respective colors to make an engraving of the entire vector drawing.
78
+ When you set the engrave action for a set of colors, only those colors will be engraved (having their respective colors), all other paths having no action set are ignored.
79
+ Also, when a path has no stroke attribute (or it is set to none) the element cannot be engraved (because it has no color) so it is interpreted as a cut action.
80
+
81
+ Option ```--pathcut``` can be used to override all stroke attributes and force cutting of all *paths* of the *SVG*.
82
+ Note that this option cannot be set at the same time as *--color_coded* above.
83
+
84
+ Option ```--nofill``` makes it possible to disable all path fills.
85
+ Options ```--origin --rotate --scale --selfcenter``` can be used to locate and transform the gcode image.
86
+ Option ```--speedmoves``` makes it possible to run engravings significantly faster and skip from one image zone to the other at maximum speed.
87
+ Option ```--noise``` suppresses stray pixels
88
+
89
+ Controlling laser power, pixel size and other settings can be done via commandline parameters but also via the following attributes (which can be set within the *.svg* file directly or within Inkscape using the XMLeditor):
90
+ ```gcode_pixelsize```, ```gcode_maxpower```, ```gcode_speed```, ```gcode_noise```, ```gcode_speedmoves```, ```gcode_overscan``` and ```gcode_showoverscan``` can be set per vector element. (Image attributes can be added within the XMLeditor (Inkscape) by using the **+**).
91
+ Note that these attributes override explicit or default commandline settings.
92
+
93
+ ### gcode optimizations
43
94
 
44
95
  Optimized gcode
45
96
  - draw pixels in one go until change of power
@@ -48,18 +99,14 @@ Optimized gcode
48
99
  - does not emit zero power (or below cutoff) pixels
49
100
 
50
101
  General optimizations
51
- - laser head has defered and sparse moves.
102
+ - laser head has deferred and sparse moves.
52
103
  (XY locations are virtual, head does not always follow)
53
104
  - moves at high speed (G0) over 10mm (default) or more zero pixels
54
105
  - low burn levels (stray pixels) can be suppressed (default off)
55
- - option *--constantburn* selects constant burn mode *M3* (for cutting and engraving) instead of default dynamic burn mode *M4*
106
+ - default --constantburn mode *gcode M3*
56
107
  - borders are drawn in parallel and in one go, following the *path* coordinates.
57
108
  - fill has support for alpha channel and 'fill-opacity'
58
109
 
59
- **Tip**: use commandline program *grblhud* *(https://github.com/johannesnoordanus/grblhud)* to have full control over gcode execution,
60
- also, program *image2gcode* has similar capabilities but handles raster images files (like *png* and *jpg*) directly.
61
-
62
- **Tip2**: another program *LaserWeb* (not made by me) is quite capable and has an excelent 3D gcode visualizer, it is able to calculate 3D paths for CNC machines, including the bit diameter.
63
110
 
64
111
  ### Install:
65
112
  ```
@@ -72,14 +119,14 @@ Some linux distributions use a managed environment in which you cannot install p
72
119
  > pipx install svg2gcode
73
120
  ```
74
121
 
75
- <sup>(*)</sup> Note that an upgraded and corrected version of this library is included.
76
122
  ### Usage:
77
123
  ```
78
124
  > svg2gcode --help
79
- usage: svg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
80
- [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>] [--noise <default:0>]
81
- [--overscan <default:0>] [--showoverscan] [--constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut]
82
- [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--fan] [-V]
125
+ usage: runsvg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
126
+ [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>]
127
+ [--noise <default:0>] [--overscan <default:0>] [--showoverscan] [--constantburn | --no-constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y]
128
+ [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan]
129
+ [-V]
83
130
  svg gcode
84
131
 
85
132
  Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.
@@ -113,7 +160,8 @@ options:
113
160
  --overscan <default:0>
114
161
  overscan image lines to avoid incorrect power levels for pixels at left and right borders, number in pixels, default off
115
162
  --showoverscan show overscan pixels (note that this is visible and part of the gcode emitted!)
116
- --constantburn set constant burn mode M3 (default set to dynamic burn mode M4); this enhances engraving quality
163
+ --constantburn, --no-constantburn
164
+ default constant burn mode (M3)
117
165
  --origin delta-x delta-y
118
166
  translate origin by vector (delta-x,delta-y) in mm (default not set, option --selfcenter cannot be used at the same time)
119
167
  --scale factor-x factor-y
@@ -126,6 +174,8 @@ options:
126
174
  machine x-axis lengh in mm
127
175
  --ymaxtravel <default:400>
128
176
  machine y-axis lengh in mm
177
+ --color_coded <default:"">
178
+ set action for path with specific stroke color "[color = [cut|engrave|ignore] *]*", example: --color_coded "black = ignore purple = cut blue = engrave"
129
179
  --fan set machine fan on
130
180
  -V, --version show version number and exit
131
181
  ```
@@ -137,8 +187,9 @@ You can also store svg2gcode settings in configuration file `~/.config/svg2gcode
137
187
  xmaxtravel= 400
138
188
  ymaxtravel= 400
139
189
  imagespeed = 6000
190
+ color_coded = "black = ignore purple = cut blue = engrave"
140
191
  ```
141
- It can be used with any parameter which takes a value, and alows to persist your laser settings.
192
+ It can be used with any parameter which takes a value, and allows to persist your laser settings.
142
193
  You can create this configuration file using an editor like vi or nano.
143
194
  An alternative (quick) way to do that is to enter:
144
195
  ```
@@ -146,6 +197,7 @@ $ mkdir ~/.config
146
197
  $ echo "xmaxtravel= 400
147
198
  ymaxtravel= 400
148
199
  imagespeed = 6000
200
+ color_coded = \"black = ignore purple = cut blue = engrave\"
149
201
  " > ~/.config/svg2gcode.toml
150
202
  ```
151
203
  (but use your own settings!)
@@ -237,7 +289,7 @@ or add 'gcode-pathcut' to the style string:
237
289
  ```
238
290
  (Note that this makes it possible to selectively cut path objects within the SVG.)
239
291
 
240
- or add *svg2gcode* option *--pathcut* to override all path stroke attributes within the SVG document
292
+ or add *svg2gcode* option *--pathcut* to override all path stroke attributes within the SVG document or use option *--color_coded* and set a cut action for the stroke color.
241
293
 
242
294
  Run *svg2gcode* (with same options) again.
243
295
  Now the gcode after conversion will look like this:
@@ -266,6 +318,7 @@ Don't worry if your lasercutter has no Z-axis, because this parameter will be ig
266
318
 
267
319
  If you have a CNC machine (which does have a Z-axis) you can mill in depth (so to speak), but you can also add - or switch to - a laser head and use the gcode to be able to really laser cut deeper!
268
320
 
321
+
269
322
  #### Create two types of gcode file
270
323
  One containing the drawings of the .svg, the other containing the images:
271
324
  ```
@@ -278,7 +331,7 @@ One containing the drawings of the .svg, the other containing the images:
278
331
 
279
332
  ### Burn mode M3/M4:
280
333
 
281
- Default *svg2gcode* uses dynamic burn mode *M4*. This can be changed by setting option *--constantburn* which selects burn mode *M3*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
334
+ Default *svg2gcode* uses constant burn mode *M3*. This can be changed by setting option *--no-constantburn* which selects burn mode *M4*. Mode *M4* is not suitable for engravings because it automatically compensates (laser)power for speed. This conflicts with the specific gcode settings given by *image2gcode* (called by *svg2gcode*) for each pixel. In fact some experiments show that *M4* causes loss of quality and image deterioration when speed is increased. On white oak images had too much black and grey which did not go away for substantially higher speed. When switched back to constant burn (*M3*) mode, the same high speed gave excellent images having a sepia (licht yellow brown) color tone.
282
335
 
283
336
  ### Notes:
284
337
  - drawing objects - within the composer - must be converted to a```path```to be translated to a gcode sequence
@@ -1,4 +1,4 @@
1
1
  """
2
2
  svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
3
3
  """
4
- __version__ = "3.2.7"
4
+ __version__ = "3.3.0"
@@ -4,6 +4,7 @@ svg2gcode: convert an image to gcode.
4
4
 
5
5
  import os
6
6
  import sys
7
+ import re
7
8
  try:
8
9
  import tomllib
9
10
  except ImportError:
@@ -16,6 +17,7 @@ from svg2gcode.svg_to_gcode.svg_parser import parse_file
16
17
  from svg2gcode.svg_to_gcode.compiler import Compiler, interfaces
17
18
 
18
19
  from svg2gcode import __version__
20
+ from svg2gcode.svg_to_gcode import css_color
19
21
 
20
22
  config_file = os.path.expanduser('~/.config/svg2gcode.toml')
21
23
 
@@ -35,10 +37,25 @@ def svg2gcode(args) -> int:
35
37
  'maximum_image_laser_power':args.imagepower, 'image_movement_speed':args.imagespeed, 'fan':args.fan,'rapid_move':args.rapidmove,
36
38
  'showimage':args.showimage, 'x_axis_maximum_travel':args.xmaxtravel,'y_axis_maximum_travel':args.ymaxtravel, 'image_noise':args.noise,
37
39
  'pass_depth':args.pass_depth, 'laser_mode':"constant" if args.constantburn else "dynamic", 'splitfile':args.splitfile, 'pathcut':args.pathcut,
38
- 'nofill':args.nofill, 'image_poweroffset':args.poweroffset, 'image_overscan':args.overscan, 'image_showoverscan':args.showoverscan})
40
+ 'nofill':args.nofill, 'image_poweroffset':args.poweroffset, 'image_overscan':args.overscan, 'image_showoverscan':args.showoverscan,
41
+ 'color_coded': args.color_coded,})
39
42
 
40
43
  compiler = init_compiler(args)
41
44
 
45
+ if args.color_coded != "":
46
+ # check color_coded argument validity (2)
47
+ pathignore, pathcut, pathengrave = compiler.color_coded_paths(True)
48
+
49
+ # a path color should be in one set only
50
+ for i in pathignore:
51
+ if i in pathcut or i in pathengrave:
52
+ print(f"argument error: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore) .")
53
+ return 1
54
+ for i in pathcut:
55
+ if i in pathengrave:
56
+ print(f"argument error: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore) .")
57
+ return 1
58
+
42
59
  # emit gcode for svg
43
60
  if args.selfcenter:
44
61
  print("pass 1")
@@ -92,6 +109,8 @@ def main() -> int:
92
109
  "pass_depth_default": 0,
93
110
  "passes_default": 1,
94
111
  "rotate_default": 0,
112
+ "colorcoded_default": "",
113
+ "constantburn_default": True,
95
114
  }
96
115
 
97
116
  if os.path.exists(config_file):
@@ -127,7 +146,7 @@ def main() -> int:
127
146
  parser.add_argument('--overscan', default=cfg["overscan_default"], metavar="<default:" +str(cfg["overscan_default"])+ ">",
128
147
  type=int, help="overscan image lines to avoid incorrect power levels for pixels at left and right borders, number in pixels, default off")
129
148
  parser.add_argument('--showoverscan', action='store_true', default=False, help='show overscan pixels (note that this is visible and part of the gcode emitted!)' )
130
- parser.add_argument('--constantburn', action='store_true', default=False, help='set constant burn mode M3 (default is dynamic burn mode M4); this enhances engraving quality')
149
+ parser.add_argument('--constantburn', action=argparse.BooleanOptionalAction, default=cfg["constantburn_default"], help='default constant burn mode (M3)')
131
150
  parser.add_argument('--origin', default=None, nargs=2, metavar=('delta-x', 'delta-y'),
132
151
  type=float, help="translate origin by vector (delta-x,delta-y) in mm (default not set, option --selfcenter cannot be used at the same time)")
133
152
  parser.add_argument('--scale', default=None, nargs=2, metavar=('factor-x', 'factor-y'),
@@ -141,12 +160,40 @@ def main() -> int:
141
160
  type=int, help="machine x-axis lengh in mm")
142
161
  parser.add_argument('--ymaxtravel', default=cfg["ymaxtravel_default"], metavar="<default:" +str(cfg["ymaxtravel_default"])+ ">",
143
162
  type=int, help="machine y-axis lengh in mm")
163
+ parser.add_argument( '--color_coded', action = 'store', default=cfg["colorcoded_default"], metavar="<default:\"" + str(cfg["colorcoded_default"])+ "\">",
164
+ type = str, help = 'set action for path with specific stroke color "[color = [cut|engrave|ignore] *]*"'
165
+ ', example: --color_coded "black = ignore purple = cut blue = engrave"' )
144
166
  parser.add_argument('--fan', action='store_true', default=False, help='set machine fan on' )
145
167
  parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__, help="show version number and exit")
146
168
 
147
169
  args = parser.parse_args()
148
170
 
149
171
  try:
172
+ if args.color_coded != "":
173
+ if args.pathcut:
174
+ print("options --color_coded and --pathcut cannot be used at the same time, program abort")
175
+ return 1
176
+ # check argument validity (1)
177
+
178
+ # category names
179
+ category = ["cut", "engrave", "ignore"]
180
+ # get css color names
181
+ colors = str([*css_color.css_color_keywords])
182
+ colors = re.sub("(,|\[|\]|\'| )", '', colors.replace(",", "|"))
183
+
184
+ # make a color list
185
+ colors = colors.split("|")
186
+
187
+ # get all names from color_coded
188
+ names_regex = "[a-zA-Z]+"
189
+ match = re.findall(names_regex, args.color_coded)
190
+ names = [i for i in match]
191
+
192
+ for name in names:
193
+ if not (name in colors or name in category):
194
+ print(f"argument error: '--color_coded {args.color_coded}' has a name '{name}' that does not correspond to a css color or category (cut|engrave|ignore).")
195
+ return 1
196
+
150
197
  if args.origin is not None and args.selfcenter:
151
198
  print("options --selfcenter and --origin cannot be used at the same time, program abort")
152
199
  return 1
@@ -40,7 +40,8 @@ SETTING = {
40
40
  "showimage", # boolean show image used for conversion to gcode
41
41
  "splitfile", # boolean return SVG path objects to <filename>.<gcext> and SVG image objects to <filename>_images.<gcext>
42
42
  "pathcut", # boolean always cut SVG path objects! use laser_power setting
43
- "nofill" # boolean ignore SVG fill attribute
43
+ "nofill", # boolean ignore SVG fill attribute
44
+ "color_coded" # string color of path determines whether it is a cut or engrave
44
45
  }
45
46
 
46
47
  # Set defaults 'minimum_laser_power', 'pass_depth', 'dwell_time', 'laser_power', 'laser_mode', 'unit', 'distance_mode'
@@ -74,7 +75,8 @@ DEFAULT_SETTING = {
74
75
  "showimage": False, # default image is not shown
75
76
  "splitfile": False, # SVG path and image objects are emitted to one file: <filename>.<gcext>
76
77
  "pathcut": False, # always cut SVG path objects! use laser_power setting
77
- "nofill": False # ignore SVG fill attribute
78
+ "nofill": False, # ignore SVG fill attribute
79
+ "color_coded": str # color of path determines whether it is a cut or engrave
78
80
  }
79
81
 
80
82
  def check_setting(setting: dict[str,Any] =None) -> bool: