You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -34,105 +34,141 @@ There are several predefined output profiles as part of the release:
34
34
-`gcode_relative`
35
35
-`csv`
36
36
-`json`
37
+
-`isvg`
37
38
38
39
Check the [source code](vpype_gcode/bundled_configs.toml) for how these profiles are defined.
39
40
40
41
## Defining Your Own Profiles
41
42
In case you want to define your own output format to make the suit your needs, it is possible to define your own profiles either in `~/.vpype.toml` or any other file. In the latter case, you must instruct vpype to load the configuration using the [`--config`](https://vpype.readthedocs.io/en/latest/reference.html#cmdoption-vpype-c) global option.
42
43
43
44
Inside the configuration file you can specify a new output profile using the following format:
44
-
```
45
+
```toml
45
46
[gwrite.my_own_plotter]
46
47
unit = "mm"
47
48
invert_y = true
48
-
header = "M3 G21\n"
49
-
prelayer = "(Start Layer)\n"
50
-
preblock = "(Start Block)\n"
51
-
move = """G00 Z5
52
-
G00 X%.4f Y%.4f
49
+
document_start = "M3 G21\n"
50
+
layer_start = "(Start Layer)\n"
51
+
linecollection_start = "(Start Block)\n"
52
+
segment_first = """G00 Z5
53
+
G00 X{x:.4f}f Y{y:.4f}
53
54
M3 S1000
54
55
G4 P0.3
55
56
G01 Z1 F3500
56
57
"""
57
-
line = """G01 X%.4f Y%.4f Z1\n"""
58
-
postblock = """G00 Z 5.0000
58
+
segment = """G01 X{x:.4f} Y{y:.4f} Z1\n"""
59
+
linecollection_end = """G00 Z 5.0000
59
60
M5 S0
60
61
G4 P0.5\n"""
61
-
footer = """M5
62
+
document_end = """M5
62
63
G00 X0.0000 Y0.0000
63
64
M2"""
64
65
```
65
66
66
67
You can use the following options inside a profile. You only need to provide the options where you need to change the default. If you want a newline character in an option, you can either use escape sequences (`\n`) or you use TOML multi line strings wrapped in `""""`.
67
68
69
+
68
70
### Output Control
69
71
-`unit`: Defines the [vpype unit](https://vpype.readthedocs.io/en/stable/fundamentals.html#units) which should be used in the output format. Defaults to `mm`.
70
72
-`invert_x`: Inverts/Mirrors the output relative to the middle point of the x axis when set to `true`. Defaults to `false`.
71
73
-`invert_y`: Inverts/Mirrors the output relative to the middle point of the y axis when set to `true`. Defaults to `false`. This option can be helpful if your output does not have the x=0, y=0 coordinates at the top left (the default) but instead at the bottom left.
72
-
-`flip_x`: Flips the X axis by multiplying all values with -1 and therefore turning them negative when set to `true`. Defaults to `false`.
73
-
-`flip_y`: Flips the Y axis by multiplying all values with -1 and therefore turning them negative when set to `true`. Defaults to `false`.
74
-
-`relative`: Use relative coordinates (so the difference to the previous point) instead of absolute coordinates when set to `true`. Defaults to `false`
75
74
76
75
### Output Format
77
-
All of the options below default to an empty text which means no output is generated.
78
-
-`header`: Output to be generated at the start of the file as a header
79
-
-`footer`: Output to be generated at the end of the file as a footer
80
-
-`preblock`: Output to be generated before a line is started
81
-
-`postblock`: Output to be generated after a line is finished.
82
-
-`move`: Output to be generated at the start of a line for its first coordinate pair.
83
-
-`line`: Output to be generated to all subsequent coordinate pairs of a line.
76
+
All of the options below default to an empty text which means no output is generated. However, if `segment_first` or `segment_last` is omitted the code from `segment` is used. If there is only one segment. `segment_first` takes priority over `segment_last`.
77
+
-`document_start`: Output to be generated at the start of the file as a document_start
78
+
-`document_end`: Output to be generated at the end of the file as a document_end
79
+
-`layer_start`: Output to be generated before a layer is started
80
+
-`layer_end`: Output to be generated after a layer is finished.
81
+
-`layer_join`: Output to be generated between two layers.
82
+
-`linecollection_start`: Output to be generated before a linecollection is started
83
+
-`linecollection_end`: Output to be generated after a linecollection is finished.
84
+
-`linecollection_join`: Output to be generated between two linecollections.
85
+
-`segment_first`: Output to be generated at the first coordinate pair.
86
+
-`segment_last`: Output to be generated at the last coordinate pair.
87
+
-`segment`: Output to be generated to all subsequent coordinate pairs of a linecollection.
88
+
89
+
### Segment formatting
90
+
`gwrite` uses `.format()` encoding which means that data elements must be encasulated in `{}` brackets. This provides a particular syntax token which differs from between elements.
91
+
For example every element except `layer_join` and `segment_join` accepts the value of `index`. You would encode that in the text as `{index:d}` the d denotes an integer value. If you need to have a `{` value in your text you would encode that as `{{` likewise you would encode a `}` as `}}`.
92
+
-`layer_start`: Accepts `index` the current layer number.
93
+
-`layer_end`: Accepts `index` the current layer number.
94
+
-`linecollection_start`: Accepts `index` the current linecollection number.
95
+
-`linecollection_end`: Accepts `index` the current linecollection number.
96
+
97
+
The segments accept a lot of values that may be useful statistics for various formats:
98
+
*`index`: index of the particular coordinate pair. eg `{index:d}`
99
+
*`x` absolute position x in floating point number. eg `{x:.4f}`
100
+
*`y` absolute position y in floating point number. eg `{y:g}`
101
+
*`dx` relative position x in floating point number. eg `{dx:f}`
102
+
*`dy` relative position y in floating point number. eg `{dy:.2f}`
103
+
*`_x` negated absolute position x in floating point number. eg `{_x:.4f}`
104
+
*`_y` negated absolute position y in floating point number. eg `{_y:g}`
105
+
*`_dx` negated relative position x in floating point number. eg `{_dx:f}`
106
+
*`_dy` negated relative position y in floating point number. eg `{_dy:.2f}`
107
+
*`ix` absolute position x in integer number. eg `{ix:d}`
108
+
*`iy` absolute position y in integer number. eg `{iy:d}`
109
+
*`idx` relative position x in integer number. eg `{idx:d}`
110
+
*`idy` relative position y in integer number. eg `{idy:d}`
111
+
112
+
Note: `idx` and `idy` are properly guarded against compounding fractional rounding errors. Moving 0.1 units 1000 times results in a location 100 units away and not zero.
113
+
84
114
85
115
## Output structure
86
116
The gwrite command gives you access to write to a variety of formats that fit the given outline. We're writing generic ascii. Since gcode can have more flavors than a Baskin Robbins™, it's best to simply draw broad strokes as to what ascii output should look like. Here we define the various elements without any regard to the gcode it will largely be producing.
87
117
```
88
-
<header>
89
-
<prelayer>
90
-
<preblock>
91
-
<move>
92
-
<line>
93
-
<line>
94
-
<line>
95
-
<line>
96
-
<postblock>
97
-
<preblock>
98
-
<move>
99
-
<line>
100
-
<line>
101
-
<line>
102
-
<line>
103
-
<postblock>
104
-
<preblock>
105
-
<move>
106
-
<line>
107
-
<line>
108
-
<line>
109
-
<line>
110
-
<postblock>
111
-
<postlayer>
112
-
<prelayer>
113
-
<preblock>
114
-
<move>
115
-
<line>
116
-
<line>
117
-
<line>
118
-
<line>
119
-
<postblock>
120
-
<preblock>
121
-
<move>
122
-
<line>
123
-
<line>
124
-
<line>
125
-
<line>
126
-
<postblock>
127
-
<preblock>
128
-
<move>
129
-
<line>
130
-
<line>
131
-
<line>
132
-
<line>
133
-
<postblock>
134
-
<postlayer>
135
-
<footer>
118
+
<document_start>
119
+
<layer_start>
120
+
<linecollection_start>
121
+
<segment_first>
122
+
<segment>
123
+
<segment>
124
+
<segment>
125
+
<segment>
126
+
<segment_last>
127
+
<linecollection_end>
128
+
<linecollection_start>
129
+
<segment_first>
130
+
<segment>
131
+
<segment>
132
+
<segment>
133
+
<segment>
134
+
<segment_last>
135
+
<linecollection_end>
136
+
<linecollection_start>
137
+
<segment_first>
138
+
<segment>
139
+
<segment>
140
+
<segment>
141
+
<segment>
142
+
<segment_last>
143
+
<linecollection_end>
144
+
<layer_end>
145
+
<layer_start>
146
+
<linecollection_start>
147
+
<segment_first>
148
+
<segment>
149
+
<segment>
150
+
<segment>
151
+
<segment>
152
+
<segment_last>
153
+
<linecollection_end>
154
+
<linecollection_start>
155
+
<segment_first>
156
+
<segment>
157
+
<segment>
158
+
<segment>
159
+
<segment>
160
+
<segment_last>
161
+
<linecollection_end>
162
+
<linecollection_start>
163
+
<segment_first>
164
+
<segment>
165
+
<segment>
166
+
<segment>
167
+
<segment>
168
+
<segment_last>
169
+
<linecollection_end>
170
+
<layer_end>
171
+
<document_end>
136
172
```
137
173
## Default Profile
138
174
To prevent having to provide the profile on every invocation of the gcode plugin, you can define a default profile which will be used when no other profile is provided on the command line. You can do so by setting the `default_profile` configuration variable inside the `gcode` section of the vpype configuration file:
@@ -154,9 +190,9 @@ Create a grid of circles, then we are `gwrite` using the `ninja` profile:
154
190
The `csv` profile is bundled with this package and defined as follows:
155
191
```
156
192
[gwrite.csv]
157
-
header = "#Operation, X-value, Y-value\n"
158
-
move = "Move, %f, %f\n"
159
-
line = "Line-to, %f, %f\n"
193
+
document_start = "#Operation, X-value, Y-value\n"
194
+
segment_first = "Move, %f, %f\n"
195
+
segment = "Line-to, %f, %f\n"
160
196
```
161
197
162
198
Using this profile you can generate a CSV for a given input into vpype:
@@ -190,49 +226,50 @@ This is the secret sauce of gwrite, it writes generic ascii which can be themed
190
226
191
227
## Convert SVG -> JSON
192
228
The `json` profile is already bundled with this package. It is defined as following:
0 commit comments