svg2gcode 4.0.9__tar.gz → 4.1.1__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.
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/PKG-INFO +42 -23
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/README.md +40 -21
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/pyproject.toml +1 -1
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/__init__.py +1 -1
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/__main__.py +65 -47
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/_compiler.py +47 -47
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/LICENSE +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/README.md +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/abcdefghijklmnop.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/gcode_output.zip +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/kye_circle_paws_orig copy.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/kye_circle_paws_orig.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/letter_B.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/lettersandsigns.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_examples/nonzero_evenodd.svg +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/LICENSE +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/__init__.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/last_compiler.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/compiler/ttt.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/css_color.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/formulas.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
- {svg2gcode-4.0.9 → svg2gcode-4.1.1}/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.
|
|
3
|
+
Version: 4.1.1
|
|
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>
|
|
@@ -10,7 +10,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
License-File: LICENSE
|
|
11
11
|
Requires-Dist: numpy >= 1.24.3, <= 2.4.6
|
|
12
12
|
Requires-Dist: Pillow >= 12.2.0
|
|
13
|
-
Requires-Dist: image2gcode >= 2.9.
|
|
13
|
+
Requires-Dist: image2gcode >= 2.9.18
|
|
14
14
|
Project-URL: Home, https://github.com/johannesnoordanus/svg2gcode
|
|
15
15
|
Import-Name: svg2gcode
|
|
16
16
|
|
|
@@ -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.
|
|
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
|
-
|
|
244
|
-
usage:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
284
|
-
|
|
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! (
|
|
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] *]*"
|
|
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|
|
|
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.
|
|
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
|
-
|
|
228
|
-
usage:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
|
268
|
-
|
|
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! (
|
|
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] *]*"
|
|
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|
|
|
304
|
+
set fan [on|on_engrave|on_cut]
|
|
286
305
|
-V, --version show version number and exit
|
|
287
306
|
```
|
|
288
307
|
|
|
@@ -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
|
-
|
|
56
|
-
if args.selfcenter:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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('--
|
|
149
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
185
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
207
|
-
|
|
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
|
-
|
|
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
|
-
|
|
235
|
+
logger.error("svg2gcode aborted!")
|
|
218
236
|
return 1
|
|
219
237
|
except Exception as error:
|
|
220
|
-
|
|
238
|
+
logger.error(error)
|
|
221
239
|
return 1
|
|
222
240
|
|
|
223
241
|
if __name__ == '__main__':
|
|
@@ -134,16 +134,12 @@ class Compiler:
|
|
|
134
134
|
|
|
135
135
|
gcode = []
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
logger.warning("Please define machine cutting area, set parameter: 'x_axis_maximum_travel' and 'y_axis_maximum_travel'")
|
|
144
|
-
gcode += ["; WARNING: Please define machine cutting area, set parameter: 'x_axis_maximum_travel' and 'y_axis_maximum_travel'\n",]
|
|
145
|
-
else:
|
|
146
|
-
gcode += [f"; WARNING: distance mode is not absolute: {self.settings['distance_mode']}\n",]
|
|
137
|
+
checkbounds = self.check_bounds()
|
|
138
|
+
if checkbounds is not None and not checkbounds:
|
|
139
|
+
logger.warning(f"Engaving or cut is not within machine bounds of"
|
|
140
|
+
f" X[0,{self.settings['x_axis_maximum_travel']}], Y[0,{self.settings['y_axis_maximum_travel']}]")
|
|
141
|
+
gcode += ["; WARNING: Engraving or cut is not within machine bounds of "
|
|
142
|
+
f"X[0,{self.settings['x_axis_maximum_travel']}], Y[0,{self.settings['y_axis_maximum_travel']}]\n",]
|
|
147
143
|
|
|
148
144
|
# add generator info and boundingbox for this code
|
|
149
145
|
|
|
@@ -159,9 +155,10 @@ class Compiler:
|
|
|
159
155
|
|
|
160
156
|
gcode += [ f"; svg2gcode {__version__} ({str(datetime.now()).split('.',maxsplit=1)[0]})",
|
|
161
157
|
f"; arguments: \n{params}",]
|
|
158
|
+
|
|
162
159
|
if self.boundingbox.get():
|
|
163
160
|
center = self.boundingbox.center()
|
|
164
|
-
gcode += [ f"; {self.boundingbox}",
|
|
161
|
+
gcode += [ f"; boundingbox: {self.boundingbox} in {self.settings['unit']}",
|
|
165
162
|
f"; boundingbox center: (X{center[0]:.{0 if center[0].is_integer() else self.precision}f},"
|
|
166
163
|
f"Y{center[1]:.{0 if center[1].is_integer() else self.precision}f})" ]
|
|
167
164
|
|
|
@@ -214,7 +211,7 @@ class Compiler:
|
|
|
214
211
|
|
|
215
212
|
return '\n'.join(header_gc + self.gcode)
|
|
216
213
|
|
|
217
|
-
def compile_to_file(self, file_name: str, svg_file_name: str, curves: list[Curve], passes=1):
|
|
214
|
+
def compile_to_file(self, file_name: str, svg_file_name: str, curves: list[Curve], passes=1, write: bool = True):
|
|
218
215
|
"""
|
|
219
216
|
A wrapper for the self.compile method. Assembles the code in the header, body and footer, saving it to a file.
|
|
220
217
|
|
|
@@ -252,38 +249,42 @@ class Compiler:
|
|
|
252
249
|
# - self.gcode (image gcode)
|
|
253
250
|
self.append_curves(curves)
|
|
254
251
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
if write:
|
|
253
|
+
# check svg file content
|
|
254
|
+
if len(self.body) == 0 and len(self.gcode) == 0:
|
|
255
|
+
logger.error(f"No paths and images to draw, input file '{svg_file_name}' is no vector file?")
|
|
258
256
|
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
header = '\n'.join(self.header) + '\n'
|
|
258
|
+
footer = '\n'.join(self.footer) + '\n'
|
|
261
259
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
260
|
+
if len(self.body) > 0:
|
|
261
|
+
# write path objects
|
|
262
|
+
with open(file_name, 'w') as file:
|
|
263
|
+
program_end = footer if (self.settings["splitfile"] or len(self.gcode) == 0) else ""
|
|
264
|
+
file.write(self.gcode_file_header() + header + self.compile(passes=passes) + '\n' + program_end)
|
|
265
|
+
logger.info(f"Path drawings written to '{file_name}'")
|
|
266
|
+
else:
|
|
267
|
+
logger.warning(f"No paths to draw, nothing to write to '{file_name}', skipping")
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
else:
|
|
276
|
-
if self.settings["splitfile"]:
|
|
277
|
-
# emit image objects to <filename>_images.<gcext>
|
|
278
|
-
with open(image_file_name, 'w') as file:
|
|
279
|
-
file.write(self.gcode_file_header() + header + self.compile_images() + '\n' + footer)
|
|
280
|
-
logger.info(f"Image drawings written to '{image_file_name}'")
|
|
269
|
+
image_file_name = file_name.rsplit('.',1)[0] + "_images." + file_name.rsplit('.',1)[1]
|
|
270
|
+
if len(self.gcode) == 0:
|
|
271
|
+
if self.settings["splitfile"]:
|
|
272
|
+
logger.warning(f"No images to draw, nothing to write to '{image_file_name}', skipping")
|
|
281
273
|
else:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
274
|
+
if self.settings["splitfile"]:
|
|
275
|
+
# emit image objects to <filename>_images.<gcext>
|
|
276
|
+
with open(image_file_name, 'w') as file:
|
|
277
|
+
file.write(self.gcode_file_header() + header + self.compile_images() + '\n' + footer)
|
|
278
|
+
logger.info(f"Image drawings written to '{image_file_name}'")
|
|
279
|
+
else:
|
|
280
|
+
# emit images objects in same file
|
|
281
|
+
open_mode = 'w' if len(self.body) == 0 else 'a+'
|
|
282
|
+
with open(file_name, open_mode) as file:
|
|
283
|
+
file.write((self.gcode_file_header() if len(self.body) == 0 else "") + '\n' + self.compile_images() + '\n' + footer)
|
|
284
|
+
logger.info(f"Added image drawings to '{file_name}'")
|
|
285
|
+
|
|
286
|
+
if len(self.body) > 0 or len(self.gcode) > 0:
|
|
287
|
+
logger.info(f"Engrave and cutting area: (lower-left:upper-right){self.boundingbox} in {self.settings['unit']}")
|
|
287
288
|
|
|
288
289
|
def append_line_chain(self, line_chain: LineSegmentChain, step: float, color: int | None = None, speed: int | None = None):
|
|
289
290
|
"""
|
|
@@ -699,14 +700,13 @@ class Compiler:
|
|
|
699
700
|
|
|
700
701
|
"""
|
|
701
702
|
return self.settings["x_axis_maximum_travel"] is not None and self.settings["y_axis_maximum_travel"] is not None
|
|
702
|
-
# logger.warning("Please define machine cutting area, set parameter: 'x_axis_maximum_travel' and 'y_axis_maximum_travel'")
|
|
703
703
|
|
|
704
|
-
def check_bounds(self):
|
|
704
|
+
def check_bounds(self) -> bool | None :
|
|
705
705
|
"""
|
|
706
706
|
Check if line segments are within the machine cutting area. Note that machine coordinate mode must
|
|
707
707
|
be absolute and machine parameters 'x_axis_maximum_travel' and 'y_axis_maximum_travel' are set, also
|
|
708
708
|
bounding box must be in the positive quadrant.
|
|
709
|
-
:return true when box is in machine area bounds
|
|
709
|
+
:return None when preconditions are not met otherwise true when box is in machine area bounds or false when not
|
|
710
710
|
"""
|
|
711
711
|
|
|
712
712
|
if self.settings["distance_mode"] == "absolute" and self.check_axis_maximum_travel() and self.boundingbox.get():
|
|
@@ -715,11 +715,11 @@ class Compiler:
|
|
|
715
715
|
|
|
716
716
|
# bbox[0] == lowerleft, bbox[1] == uperright, bbox[0/1][0] == x, bbox[0/1][1] == y
|
|
717
717
|
# lower left x and y >= 0 and upperright x and y <= resp. machine max x and y
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
718
|
+
if bbox[0][0] >= 0 and bbox[0][1] >=0:
|
|
719
|
+
return ((bbox[1][0] * (25.4 if self.settings["unit"] == "inch" else 1) <= machine_max.x) and
|
|
720
|
+
(bbox[1][1] * (25.4 if self.settings["unit"] == "inch" else 1) <= machine_max.y))
|
|
721
721
|
|
|
722
|
-
return
|
|
722
|
+
return None
|
|
723
723
|
|
|
724
724
|
def append_curves(self, curves: list[Curve]):
|
|
725
725
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|