svg2gcode 4.0.8__tar.gz → 4.1.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 (44) hide show
  1. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/PKG-INFO +41 -22
  2. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/README.md +40 -21
  3. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/__init__.py +1 -1
  4. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/__main__.py +65 -47
  5. svg2gcode-4.1.0/svg2gcode/svg_to_gcode/compiler/_compiler.py +1176 -0
  6. svg2gcode-4.1.0/svg2gcode/svg_to_gcode/compiler/ttt.py +1204 -0
  7. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/LICENSE +0 -0
  8. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/pyproject.toml +0 -0
  9. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/README.md +0 -0
  10. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/abcdefghijklmnop.svg +0 -0
  11. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/gcode_output.zip +0 -0
  12. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/kye_circle_paws_orig copy.svg +0 -0
  13. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/kye_circle_paws_orig.svg +0 -0
  14. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/letter_B.svg +0 -0
  15. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/lettersandsigns.svg +0 -0
  16. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_examples/nonzero_evenodd.svg +0 -0
  17. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/LICENSE +0 -0
  18. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/__init__.py +0 -0
  19. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
  20. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
  21. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
  22. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
  23. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
  24. /svg2gcode-4.0.8/svg2gcode/svg_to_gcode/compiler/_compiler.py → /svg2gcode-4.1.0/svg2gcode/svg_to_gcode/compiler/last_compiler.py +0 -0
  25. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/css_color.py +0 -0
  26. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/formulas.py +0 -0
  27. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
  28. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
  29. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
  30. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
  31. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
  32. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
  33. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
  34. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
  35. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
  36. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
  37. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
  38. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
  39. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
  40. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +0 -0
  41. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +0 -0
  42. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
  43. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
  44. {svg2gcode-4.0.8 → svg2gcode-4.1.0}/svg2gcode/svg_to_gcode/svg_parser/debug_methods.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: svg2gcode
3
- Version: 4.0.8
3
+ Version: 4.1.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>
@@ -20,10 +20,35 @@ Import-Name: svg2gcode
20
20
 
21
21
  Vector graphics files can be manipulated - scaled, rotated, transformed - and be converted to optimised gcode which can be directly used on your laser engraver/cutter. Properties like line thickness, fill, color and even color transparency are all taken into account. They are vector based.
22
22
 
23
- Unique is that bitmap images are also supported and drawn alongside and at the same scaling and position as defined in the *.svg* file. Specific lines within the vector drawings can be identified by color name or code and assigned actions like engrave, cut or ignore. All from one command.
23
+ Unique is that bitmap images are also supported and drawn alongside and at the same scaling and position as defined in the *.svg* file. Specific lines within the vector drawings can be identified by color name or code and assigned actions like engrave, cut or ignore. Additionally the origin of the engraving and cutting area can be set to center or another machine location indicated.
24
+ This all from one command.
24
25
 
25
26
  *svg2gcode* makes use of library *image2gcode* for bitmap conversion to gcode and an updated and corrected version of library *SvgToGcode* for parsing (reading, interpreting) vector graphics files.<sup>(1)</sup>.
26
27
 
28
+ --
29
+
30
+ Exciting times as I have discovered that deep black laser engravings are possible on polished (stainless)steel using a 10W 0.08 mm<sup>(2)</sup> - practically 0.1 mm<sup>(2)</sup> - beam laser. Settings: speed 200mm/min and intensity 1000 (full power).<br>
31
+ I can get incredible detail in text and have good images.
32
+
33
+ ### Version 4.1 is out now!
34
+ **svg2gcode 4.1** has improved control over the gcode end result.<br>Option ```--origin machine-x machine-y``` now sets the *lower left* of the engraving and cutting area to the machine location indicated. When set to *0 0* the engraving and cutting area will be immediately above the machine x axis and immediately to the right of the machine y axis which makes it easy to place the object to engrave.<br>
35
+ Additionally the unaltered option ```--selfcenter``` makes it possible to easily place the object to engrave using the center as alignment.
36
+ Also program reporting is streamlined a bit and now shows additional information about the machine location of the engraving and cut area:
37
+ ```
38
+ svg2gcode --origin 0 0 tag_Kye_back.svg tag_Kye_back.gc
39
+ [INFO] Path drawings written to 'tag_Kye_back.gc'
40
+ [INFO] Added image drawings to 'tag_Kye_back.gc'
41
+ [INFO] Engrave and cutting area: (lower-left:upper-right)(X-0.0,Y0.0:X25.4,Y25.4) in mm
42
+ ```
43
+ --
44
+
45
+ I put a lot of work into this program to get it right, but it might be that you encounter errors in which case you can contact me or put in an issue at *https://github.com/johannesnoordanus/svg2gcode*. You can also do a feature request in the same manner.
46
+ Note that this projects is fully hand coded by me and that I intent to support it for many years to come.
47
+
48
+ Have fun using it.
49
+
50
+ Johannes
51
+
27
52
  ### Version 4.0 is out now!
28
53
  **svg2gcode 4.0** has a vastly improved *stroke* and *fill* and is even easier to control.
29
54
  Lines of a certain width are now drawn almost perfectly in a vector like manner.
@@ -57,13 +82,6 @@ Fan control is also improved, it is now possible - apart from setting it *on* or
57
82
 
58
83
  The latest improvement in version 4.0.7 is that *fill* now takes line thickness into account. So they - fill and border - don't overlap. Normally in display rendering of graphics a fill followed by drawing of the edge makes a perfect fill optically, but in case of laser engraving this does not work because some lines overlap and cause twice the burn level and so have a somewhat deeper black which can be visible.
59
84
 
60
- I put a lot of work into this program to get it right, but it might be that you encounter errors in which case you can contact me or put in an issue at *https://github.com/johannesnoordanus/svg2gcode*. You can also do a feature request in the same manner.
61
-
62
- Have fun using it.
63
-
64
- Johannes
65
-
66
-
67
85
  <sup>(2)</sup> I recommend using a recent Inkscape (v.1.4.4 and higher) and use it to create content to display on your laser machine. It is far superior and qualitatively better (superior rendering) than 'all in' software is able to provide. To learn using Inkscape is valuable because it is allround applicable and you have a maximum of expressive capabilities. (I'm not connected in any way to the free and open source software project Inkscape, by the way. I just think that it is smart to use the software that works best.)<br>
68
86
  <sup>(3)</sup> It is also possible to leave out option '--color-coded' because engraving is the default.
69
87
 
@@ -240,12 +258,13 @@ Some linux distributions use a managed environment in which you cannot install p
240
258
 
241
259
  ### Usage:
242
260
  ```
243
- > svg2gcode --help
244
- usage: svg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>] [--poweroffset <default:0>]
245
- [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>] [--noise <default:0>] [--overscan <default:0>] [--showoverscan]
246
- [--constantburn | --no-constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--fillrule <default:"nonzero">]
247
- [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan <default:"off">] [-V]
248
- svg gcode
261
+ vg2gcode --help
262
+ usage: runsvg2gcode [-h] [--showimage] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
263
+ [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>]
264
+ [--noise <default:0>] [--overscan <default:0>] [--showoverscan] [--constantburn | --no-constantburn] [--selfcenter] [--origin origin-x origin-y]
265
+ [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--fillrule <default:"nonzero">] [--xmaxtravel <default:300>]
266
+ [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan <default:"off">] [-V]
267
+ svg gcode
249
268
 
250
269
  Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.
251
270
 
@@ -256,7 +275,6 @@ positional arguments:
256
275
  options:
257
276
  -h, --help show this help message and exit
258
277
  --showimage show b&w converted image
259
- --selfcenter self center the gcode (--origin cannot be used at the same time)
260
278
  --pixelsize <default:0.1>
261
279
  pixel size in mm (XY-axis): each image pixel is drawn this size
262
280
  --imagespeed <default:800>
@@ -280,13 +298,14 @@ options:
280
298
  --showoverscan show overscan pixels (note that this is visible and part of the gcode emitted!)
281
299
  --constantburn, --no-constantburn
282
300
  default constant burn mode (M3)
283
- --origin delta-x delta-y
284
- translate origin by vector (delta-x,delta-y) in mm (default not set, option --selfcenter cannot be used at the same time)
301
+ --selfcenter self center the gcode; (0,0) is at the center of the engrave and cut area, option --origin cannot be used at the same time
302
+ --origin origin-x origin-y
303
+ set lower left of engrave and cut area to (origin-x,origin-y), option --selfcenter cannot be used at the same time
285
304
  --scale factor-x factor-y
286
305
  scale svg with (factor-x,factor-y) (default not set)
287
306
  --rotate <default:0> number of degrees to rotate
288
307
  --splitfile split gcode output of SVG path and image objects
289
- --pathcut alway cut SVG path objects! (use laser power set with option --cuttingpower)
308
+ --pathcut alway cut SVG path objects! (uses --cuttingpower)
290
309
  --nofill ignore SVG fill attribute
291
310
  --fillrule <default:"nonzero">
292
311
  set fill rule to [nonzero|evenodd]
@@ -295,10 +314,10 @@ options:
295
314
  --ymaxtravel <default:400>
296
315
  machine y-axis lengh in mm
297
316
  --color_coded <default:"">
298
- set action for path with specific stroke color "[[color|allothercolors] = [cut|engrave|ignore] *]*", example: --color_coded "black = ignore purple = cut blue = engrave allothercolors
299
- = ignore"
317
+ set action for path with specific stroke color "[[color|allothercolors] = [cut|engrave|ignore] *]*"
318
+ , example: --color_coded "black = ignore purple = cut blue = engrave allothercolors = ignore"
300
319
  --fan <default:"off">
301
- set fan [on|off|on_engrave|on_cut]
320
+ set fan [on|on_engrave|on_cut]
302
321
  -V, --version show version number and exit
303
322
  ```
304
323
 
@@ -4,10 +4,35 @@
4
4
 
5
5
  Vector graphics files can be manipulated - scaled, rotated, transformed - and be converted to optimised gcode which can be directly used on your laser engraver/cutter. Properties like line thickness, fill, color and even color transparency are all taken into account. They are vector based.
6
6
 
7
- Unique is that bitmap images are also supported and drawn alongside and at the same scaling and position as defined in the *.svg* file. Specific lines within the vector drawings can be identified by color name or code and assigned actions like engrave, cut or ignore. All from one command.
7
+ Unique is that bitmap images are also supported and drawn alongside and at the same scaling and position as defined in the *.svg* file. Specific lines within the vector drawings can be identified by color name or code and assigned actions like engrave, cut or ignore. Additionally the origin of the engraving and cutting area can be set to center or another machine location indicated.
8
+ This all from one command.
8
9
 
9
10
  *svg2gcode* makes use of library *image2gcode* for bitmap conversion to gcode and an updated and corrected version of library *SvgToGcode* for parsing (reading, interpreting) vector graphics files.<sup>(1)</sup>.
10
11
 
12
+ --
13
+
14
+ Exciting times as I have discovered that deep black laser engravings are possible on polished (stainless)steel using a 10W 0.08 mm<sup>(2)</sup> - practically 0.1 mm<sup>(2)</sup> - beam laser. Settings: speed 200mm/min and intensity 1000 (full power).<br>
15
+ I can get incredible detail in text and have good images.
16
+
17
+ ### Version 4.1 is out now!
18
+ **svg2gcode 4.1** has improved control over the gcode end result.<br>Option ```--origin machine-x machine-y``` now sets the *lower left* of the engraving and cutting area to the machine location indicated. When set to *0 0* the engraving and cutting area will be immediately above the machine x axis and immediately to the right of the machine y axis which makes it easy to place the object to engrave.<br>
19
+ Additionally the unaltered option ```--selfcenter``` makes it possible to easily place the object to engrave using the center as alignment.
20
+ Also program reporting is streamlined a bit and now shows additional information about the machine location of the engraving and cut area:
21
+ ```
22
+ svg2gcode --origin 0 0 tag_Kye_back.svg tag_Kye_back.gc
23
+ [INFO] Path drawings written to 'tag_Kye_back.gc'
24
+ [INFO] Added image drawings to 'tag_Kye_back.gc'
25
+ [INFO] Engrave and cutting area: (lower-left:upper-right)(X-0.0,Y0.0:X25.4,Y25.4) in mm
26
+ ```
27
+ --
28
+
29
+ I put a lot of work into this program to get it right, but it might be that you encounter errors in which case you can contact me or put in an issue at *https://github.com/johannesnoordanus/svg2gcode*. You can also do a feature request in the same manner.
30
+ Note that this projects is fully hand coded by me and that I intent to support it for many years to come.
31
+
32
+ Have fun using it.
33
+
34
+ Johannes
35
+
11
36
  ### Version 4.0 is out now!
12
37
  **svg2gcode 4.0** has a vastly improved *stroke* and *fill* and is even easier to control.
13
38
  Lines of a certain width are now drawn almost perfectly in a vector like manner.
@@ -41,13 +66,6 @@ Fan control is also improved, it is now possible - apart from setting it *on* or
41
66
 
42
67
  The latest improvement in version 4.0.7 is that *fill* now takes line thickness into account. So they - fill and border - don't overlap. Normally in display rendering of graphics a fill followed by drawing of the edge makes a perfect fill optically, but in case of laser engraving this does not work because some lines overlap and cause twice the burn level and so have a somewhat deeper black which can be visible.
43
68
 
44
- I put a lot of work into this program to get it right, but it might be that you encounter errors in which case you can contact me or put in an issue at *https://github.com/johannesnoordanus/svg2gcode*. You can also do a feature request in the same manner.
45
-
46
- Have fun using it.
47
-
48
- Johannes
49
-
50
-
51
69
  <sup>(2)</sup> I recommend using a recent Inkscape (v.1.4.4 and higher) and use it to create content to display on your laser machine. It is far superior and qualitatively better (superior rendering) than 'all in' software is able to provide. To learn using Inkscape is valuable because it is allround applicable and you have a maximum of expressive capabilities. (I'm not connected in any way to the free and open source software project Inkscape, by the way. I just think that it is smart to use the software that works best.)<br>
52
70
  <sup>(3)</sup> It is also possible to leave out option '--color-coded' because engraving is the default.
53
71
 
@@ -224,12 +242,13 @@ Some linux distributions use a managed environment in which you cannot install p
224
242
 
225
243
  ### Usage:
226
244
  ```
227
- > svg2gcode --help
228
- usage: svg2gcode [-h] [--showimage] [--selfcenter] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>] [--poweroffset <default:0>]
229
- [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>] [--noise <default:0>] [--overscan <default:0>] [--showoverscan]
230
- [--constantburn | --no-constantburn] [--origin delta-x delta-y] [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--fillrule <default:"nonzero">]
231
- [--xmaxtravel <default:300>] [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan <default:"off">] [-V]
232
- svg gcode
245
+ vg2gcode --help
246
+ usage: runsvg2gcode [-h] [--showimage] [--pixelsize <default:0.1>] [--imagespeed <default:800>] [--cuttingspeed <default:1000>] [--imagepower <default:300>]
247
+ [--poweroffset <default:0>] [--cuttingpower <default:850>] [--passes <default:1>] [--pass_depth <default:0>] [--rapidmove <default:10>]
248
+ [--noise <default:0>] [--overscan <default:0>] [--showoverscan] [--constantburn | --no-constantburn] [--selfcenter] [--origin origin-x origin-y]
249
+ [--scale factor-x factor-y] [--rotate <default:0>] [--splitfile] [--pathcut] [--nofill] [--fillrule <default:"nonzero">] [--xmaxtravel <default:300>]
250
+ [--ymaxtravel <default:400>] [--color_coded <default:"">] [--fan <default:"off">] [-V]
251
+ svg gcode
233
252
 
234
253
  Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.
235
254
 
@@ -240,7 +259,6 @@ positional arguments:
240
259
  options:
241
260
  -h, --help show this help message and exit
242
261
  --showimage show b&w converted image
243
- --selfcenter self center the gcode (--origin cannot be used at the same time)
244
262
  --pixelsize <default:0.1>
245
263
  pixel size in mm (XY-axis): each image pixel is drawn this size
246
264
  --imagespeed <default:800>
@@ -264,13 +282,14 @@ options:
264
282
  --showoverscan show overscan pixels (note that this is visible and part of the gcode emitted!)
265
283
  --constantburn, --no-constantburn
266
284
  default constant burn mode (M3)
267
- --origin delta-x delta-y
268
- translate origin by vector (delta-x,delta-y) in mm (default not set, option --selfcenter cannot be used at the same time)
285
+ --selfcenter self center the gcode; (0,0) is at the center of the engrave and cut area, option --origin cannot be used at the same time
286
+ --origin origin-x origin-y
287
+ set lower left of engrave and cut area to (origin-x,origin-y), option --selfcenter cannot be used at the same time
269
288
  --scale factor-x factor-y
270
289
  scale svg with (factor-x,factor-y) (default not set)
271
290
  --rotate <default:0> number of degrees to rotate
272
291
  --splitfile split gcode output of SVG path and image objects
273
- --pathcut alway cut SVG path objects! (use laser power set with option --cuttingpower)
292
+ --pathcut alway cut SVG path objects! (uses --cuttingpower)
274
293
  --nofill ignore SVG fill attribute
275
294
  --fillrule <default:"nonzero">
276
295
  set fill rule to [nonzero|evenodd]
@@ -279,10 +298,10 @@ options:
279
298
  --ymaxtravel <default:400>
280
299
  machine y-axis lengh in mm
281
300
  --color_coded <default:"">
282
- set action for path with specific stroke color "[[color|allothercolors] = [cut|engrave|ignore] *]*", example: --color_coded "black = ignore purple = cut blue = engrave allothercolors
283
- = ignore"
301
+ set action for path with specific stroke color "[[color|allothercolors] = [cut|engrave|ignore] *]*"
302
+ , example: --color_coded "black = ignore purple = cut blue = engrave allothercolors = ignore"
284
303
  --fan <default:"off">
285
- set fan [on|off|on_engrave|on_cut]
304
+ set fan [on|on_engrave|on_cut]
286
305
  -V, --version show version number and exit
287
306
  ```
288
307
 
@@ -1,4 +1,4 @@
1
1
  """
2
2
  svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
3
3
  """
4
- __version__ = "4.0.8"
4
+ __version__ = "4.1.0"
@@ -23,8 +23,29 @@ from svg2gcode.svg_to_gcode import css_color
23
23
 
24
24
  config_file = os.path.expanduser('~/.config/svg2gcode.toml')
25
25
 
26
+ class OnceFilter(logging.Filter):
27
+ """log same messages only once"""
28
+ def __init__(self):
29
+ super().__init__()
30
+ self.logged_messages = set()
31
+
32
+ def filter(self, record):
33
+ # Use message string is key
34
+ log_entry = record.getMessage()
35
+ if log_entry in self.logged_messages:
36
+ # duplicate if message in set()
37
+ return False # Do not log
38
+ self.logged_messages.add(log_entry)
39
+ return True # Log it
40
+
26
41
  # Set logging global disable flag
27
42
  ##logging.disable(logging.CRITICAL + 1)
43
+ # Setup logger, add filter to display messages only once.
44
+ logger = logging.getLogger(__name__)
45
+ logger.addFilter(OnceFilter())
46
+ logging.basicConfig(format="[%(levelname)s] %(message)s")
47
+ logger.setLevel(logging.INFO)
48
+
28
49
 
29
50
  # Set warnings disable flag (use python option -W to enable warnings)
30
51
  if not sys.warnoptions:
@@ -51,37 +72,33 @@ def svg2gcode(args) -> int:
51
72
  'color_coded': args.color_coded,})
52
73
 
53
74
  compiler = init_compiler(args)
54
-
55
- # emit gcode for svg
56
- if args.selfcenter:
57
- print("pass 1")
58
- compiler.compile_to_file(args.gcode, args.svg, parse_file(args.svg, delta_origin=args.origin, scale_factor=args.scale, rotate_deg=args.rotate), passes=args.passes)
59
-
60
- if args.selfcenter:
61
- # remove output files(s)
62
- filename = args.gcode
63
-
64
- if os.path.isfile(filename):
65
- os.remove(filename)
66
- image_filename = filename.rsplit('.',1)[0] + "_images." + filename.rsplit('.',1)[1]
67
- if os.path.isfile(image_filename):
68
- os.remove(image_filename)
69
-
70
- center = compiler.boundingbox.center()
71
- center = (round(center[0], compiler.precision), round(center[1], compiler.precision))
72
- print(f"center: {center}")
73
- center = (-center[0], -center[1])
74
-
75
- # init compiler again
76
- compiler = init_compiler(args)
77
-
78
- # now run with origin set to center
79
- # emit gcode for svg
80
- print("pass 2")
81
- compiler.compile_to_file(args.gcode, args.svg, parse_file(args.svg, delta_origin=center, scale_factor=args.scale, rotate_deg=args.rotate), passes=args.passes)
82
- center = compiler.boundingbox.center()
83
- center = (round(center[0], compiler.precision), round(center[1], compiler.precision))
84
- print(f"new center: {center}")
75
+ compiler.compile_to_file(args.gcode, args.svg, parse_file(args.svg, scale_factor=args.scale, rotate_deg=args.rotate), passes=args.passes, write=not(args.selfcenter or args.origin))
76
+
77
+ if args.selfcenter or args.origin:
78
+ if args.selfcenter:
79
+ center = compiler.boundingbox.center()
80
+ center = (round(center[0], compiler.precision), round(center[1], compiler.precision))
81
+ center = (-center[0], -center[1])
82
+
83
+ # init compiler again
84
+ compiler = init_compiler(args)
85
+
86
+ # now run with origin set to center
87
+ # emit gcode for svg
88
+ compiler.compile_to_file(args.gcode, args.svg, parse_file(args.svg, delta_origin=center, scale_factor=args.scale, rotate_deg=args.rotate), passes=args.passes)
89
+ else:
90
+ # get origin 0,0
91
+ bbox = compiler.boundingbox.get()
92
+ bbox = (round(bbox.lowerleft.x, compiler.precision), round(bbox.lowerleft.y, compiler.precision))
93
+ # set new origin for bbox relative to 0,0
94
+ origin = (-bbox[0] + args.origin[0], -bbox[1] + args.origin[1])
95
+
96
+ # init compiler again
97
+ compiler = init_compiler(args)
98
+
99
+ # Now compile and set lower left of engrave and cut area bounding box to args origin
100
+ # emit gcode for svg
101
+ compiler.compile_to_file(args.gcode, args.svg, parse_file(args.svg, delta_origin=origin, scale_factor=args.scale, rotate_deg=args.rotate), passes=args.passes)
85
102
 
86
103
  return 0
87
104
 
@@ -116,11 +133,11 @@ def main() -> int:
116
133
  cfg.update({k + '_default': v for k,v in tomllib.load(f).items()})
117
134
 
118
135
  # Define command line argument interface
119
- parser = argparse.ArgumentParser(description='Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.')
136
+ parser = argparse.ArgumentParser(description='Convert svg to gcode for GRBL v1.1 compatible diode laser engravers.',
137
+ formatter_class=argparse.RawTextHelpFormatter )
120
138
  parser.add_argument('svg', type=str, help='svg file to be converted to gcode')
121
139
  parser.add_argument('gcode', type=str, help='gcode output file')
122
140
  parser.add_argument('--showimage', action='store_true', default=False, help='show b&w converted image' )
123
- parser.add_argument('--selfcenter', action='store_true', default=False, help='self center the gcode (--origin cannot be used at the same time)' )
124
141
  parser.add_argument('--pixelsize', default=cfg["pixelsize_default"], metavar="<default:" + str(cfg["pixelsize_default"])+">",
125
142
  type=float, help="pixel size in mm (XY-axis): each image pixel is drawn this size")
126
143
  parser.add_argument('--imagespeed', default=cfg["imagespeed_default"], metavar="<default:" + str(cfg["imagespeed_default"])+">",
@@ -145,8 +162,9 @@ def main() -> int:
145
162
  type=int, help="overscan image lines to avoid incorrect power levels for pixels at left and right borders, number in pixels, default off")
146
163
  parser.add_argument('--showoverscan', action='store_true', default=False, help='show overscan pixels (note that this is visible and part of the gcode emitted!)' )
147
164
  parser.add_argument('--constantburn', action=argparse.BooleanOptionalAction, default=cfg["constantburn_default"], help='default constant burn mode (M3)')
148
- parser.add_argument('--origin', default=None, nargs=2, metavar=('delta-x', 'delta-y'),
149
- 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)")
165
+ parser.add_argument('--selfcenter', action='store_true', default=False, help='self center the gcode; (0,0) is at the center of the engrave and cut area, option --origin cannot be used at the same time' )
166
+ parser.add_argument('--origin', default=None, nargs=2, metavar=('origin-x', 'origin-y'),
167
+ type=float, help="set lower left of engrave and cut area to (origin-x,origin-y), option --selfcenter cannot be used at the same time")
150
168
  parser.add_argument('--scale', default=None, nargs=2, metavar=('factor-x', 'factor-y'),
151
169
  type=float, help="scale svg with (factor-x,factor-y) (default not set)")
152
170
  parser.add_argument('--rotate', default=cfg["rotate_default"], metavar="<default:" +str(cfg["rotate_default"])+ ">",
@@ -161,8 +179,8 @@ def main() -> int:
161
179
  parser.add_argument('--ymaxtravel', default=cfg["ymaxtravel_default"], metavar="<default:" +str(cfg["ymaxtravel_default"])+ ">",
162
180
  type=int, help="machine y-axis lengh in mm")
163
181
  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|allothercolors] = [cut|engrave|ignore] *]*"'
165
- ', example: --color_coded "black = ignore purple = cut blue = engrave allothercolors = ignore"' )
182
+ type = str, help = ("set action for path with specific stroke color \"[[color|allothercolors] = [cut|engrave|ignore] *]*\"\n"
183
+ ', example: --color_coded "black = ignore purple = cut blue = engrave allothercolors = ignore"'))
166
184
  parser.add_argument('--fan', action = 'store', default=cfg["fan_default"], metavar="<default:\"" + str(cfg["fan_default"])+ "\">",
167
185
  type = str, help = 'set fan [on|on_engrave|on_cut]')
168
186
  parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__, help="show version number and exit")
@@ -172,7 +190,7 @@ def main() -> int:
172
190
  try:
173
191
  if args.color_coded != "":
174
192
  if args.pathcut:
175
- print("options --color_coded and --pathcut cannot be used at the same time, program abort")
193
+ logger.error("options --color_coded and --pathcut cannot be used at the same time, program abort")
176
194
  return 1
177
195
 
178
196
  # check color_coded argument validity (1)
@@ -181,8 +199,8 @@ def main() -> int:
181
199
  cc = re.sub(",", '', args.color_coded)
182
200
  fm = re.fullmatch("( *[^ ]* *= *(cut|engrave|ignore))+", cc)
183
201
  if not fm:
184
- print(f"syntax error in argument: '--color_coded {args.color_coded}', argument should be similar to: "
185
- f"'--color_coded \"black = ignore purple = cut blue = engrave\"'")
202
+ logger.error(f"syntax error in argument: '--color_coded {args.color_coded}', argument should be similar to: "
203
+ f"'--color_coded \"black = ignore purple = cut blue = engrave\"'")
186
204
  return 1
187
205
 
188
206
  cc = fm.group(0)
@@ -193,31 +211,31 @@ def main() -> int:
193
211
  # a path color should be in one set only
194
212
  for i in pathignore:
195
213
  if i in pathcut or i in pathengrave:
196
- print(f"error in argument: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore).")
214
+ logger.error(f"error in argument: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore).")
197
215
  return 1
198
216
  for i in pathcut:
199
217
  if i in pathengrave:
200
- print(f"error in argument: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore).")
218
+ logger.error(f"error in argument: '--color_coded \"{args.color_coded}\"' has a path color '{i}' set in multiple categories (cut|engrave|ignore).")
201
219
  return 1
202
220
 
203
221
  # check validity of color argument, either "allothercolors" or a valid color value e.g. one of '#hex', 'rgb(', 'rgba(', 'hsl(' and 'hsla(' color schemes.
204
222
  for i in pathignore + pathcut + pathengrave:
205
223
  if not (i == "allothercolors" or css_color.parse_css_color(i, fallback = False, warning = False)):
206
- print(f"error in argument: '--color_coded \"{args.color_coded}\"':")
207
- print(f"- invalid color '{i}', color must be of scheme '#hex', 'rgb', 'rgba', 'hsl', 'hsla' or set to 'allothercolors'.")
224
+ logger.error(f"error in argument: '--color_coded \"{args.color_coded}\"':")
225
+ logger.error(f"- invalid color '{i}', color must be of scheme '#hex', 'rgb', 'rgba', 'hsl', 'hsla' or set to 'allothercolors'.")
208
226
  return 1
209
227
 
210
228
  if args.origin is not None and args.selfcenter:
211
- print("options --selfcenter and --origin cannot be used at the same time, program abort")
229
+ logger.error("options --selfcenter and --origin cannot be used at the same time, program abort")
212
230
  return 1
213
231
 
214
232
  return svg2gcode(args)
215
233
 
216
234
  except KeyboardInterrupt:
217
- print("svg2gcode aborted!")
235
+ logger.error("svg2gcode aborted!")
218
236
  return 1
219
237
  except Exception as error:
220
- print(error)
238
+ logger.error(error)
221
239
  return 1
222
240
 
223
241
  if __name__ == '__main__':