Skip to content

Commit 888cc72

Browse files
committed
Readme Update.
1 parent 3ec113e commit 888cc72

1 file changed

Lines changed: 141 additions & 104 deletions

File tree

README.md

Lines changed: 141 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -34,105 +34,141 @@ There are several predefined output profiles as part of the release:
3434
- `gcode_relative`
3535
- `csv`
3636
- `json`
37+
- `isvg`
3738

3839
Check the [source code](vpype_gcode/bundled_configs.toml) for how these profiles are defined.
3940

4041
## Defining Your Own Profiles
4142
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.
4243

4344
Inside the configuration file you can specify a new output profile using the following format:
44-
```
45+
```toml
4546
[gwrite.my_own_plotter]
4647
unit = "mm"
4748
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}
5354
M3 S1000
5455
G4 P0.3
5556
G01 Z1 F3500
5657
"""
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
5960
M5 S0
6061
G4 P0.5\n"""
61-
footer = """M5
62+
document_end = """M5
6263
G00 X0.0000 Y0.0000
6364
M2"""
6465
```
6566

6667
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 `""""`.
6768

69+
6870
### Output Control
6971
- `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`.
7072
- `invert_x`: Inverts/Mirrors the output relative to the middle point of the x axis when set to `true`. Defaults to `false`.
7173
- `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`
7574

7675
### 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+
84114

85115
## Output structure
86116
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.
87117
```
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>
136172
```
137173
## Default Profile
138174
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:
154190
The `csv` profile is bundled with this package and defined as follows:
155191
```
156192
[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"
160196
```
161197

162198
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
190226

191227
## Convert SVG -> JSON
192228
The `json` profile is already bundled with this package. It is defined as following:
193-
```
229+
```toml
194230
[gwrite.json]
195-
header = "{\n"
196-
footer = "}\n"
197-
prelayer = "\t\"Layer\": {\n"
198-
preblock = "\t\t\"Block\": [\n"
199-
move = "\t\t{\n\t\t\t\"X\": %d,\n\t\t\t\"Y\": %d\n\t\t}"
200-
line = ",\n\t\t{\n\t\t\t\"X\": %d,\n\t\t\t\"Y\": %d\n\t\t}"
201-
postblock = "\n\t\t],\n"
202-
postlayer = "\t},\n"
231+
document_start = "{{"
232+
document_end = "}}\n"
233+
linecollection_join = ","
234+
layer_join = ","
235+
layer_start = "\n\t\"Layer\": {{"
236+
layer_end = "\t}}\n"
237+
linecollection_start = "\n\t\t\"LineCollection{index:d}\": [\n"
238+
linecollection_end = "\n\t\t]"
239+
segment = "\t\t{{\n\t\t\t\"X\": {ix:d},\n\t\t\t\"Y\": {iy:d}\n\t\t}},\n"
240+
segment_last = "\t\t{{\n\t\t\t\"X\": {ix:d},\n\t\t\t\"Y\": {iy:d}\n\t\t}}"
203241
```
204242
Using this profile, you can generate JSON for the rectangle:
205243
`vpype rect 0 0 100 100 gwrite -p json test.json`
206244

207245
```json
208246
{
209-
"Layer": {
210-
"Block": [
211-
{
212-
"X": 0,
213-
"Y": 0
214-
},
215-
{
216-
"X": 0,
217-
"Y": 100
218-
},
219-
{
220-
"X": 100,
221-
"Y": 100
222-
},
223-
{
224-
"X": 100,
225-
"Y": 0
226-
},
227-
{
228-
"X": 0,
229-
"Y": 0
230-
}
231-
],
232-
},
247+
"Layer": {
248+
"LineCollection0": [
249+
{
250+
"X": 0,
251+
"Y": 0
252+
},
253+
{
254+
"X": 0,
255+
"Y": 26
256+
},
257+
{
258+
"X": 26,
259+
"Y": 26
260+
},
261+
{
262+
"X": 26,
263+
"Y": 0
264+
},
265+
{
266+
"X": 0,
267+
"Y": 0
268+
}
269+
] }
233270
}
234271
```
235272

236-
Strictly speaking json shouldn't have the last 2 commas there, but it's for demonstration purposes.
273+
Which is valid JSON.
237274

238275

0 commit comments

Comments
 (0)