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
Added support for property substitution in profile definition.
Layer and global property may now be used in profile definition (e.g. `{vp_color}`). To avoid error when they are missing, default value may be provided by the profile (`default_values` key) or in the CLI (`--default` option). The latter is not recommended for non-string value as number-specific formatting (`{...:d}`, etc.) would break.
The following change were also introduced:
- bumped vpype to 1.10
- updated list of compatible python version
- removed `flush()` and `close()` on file (done automatically by click)
- print `info` to stderr
- applied black formatting on gwrite.py
Some of the changes above improves the use of `-` as path to output to stdout instead of in a file.
Copy file name to clipboardExpand all lines: README.md
+75-26Lines changed: 75 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,11 @@ All of the options below default to an empty text which means no output is gener
111
111
### Segment formatting
112
112
`gwrite` uses `.format()` encoding which means that data elements must be encapsulated in `{}` brackets. This provides a particular syntax token which differs from between elements.
113
113
For example every element 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 `}}`.
114
-
-`layer_start`, `layer_end` and `layer_join`: Accepts `x`, `y`, `ix`, `iy`, `index`, `index1`, `layer_index`, `layer_index1`, `layer_id`, and `filename`.
114
+
115
+
-`document_start` and `document_end` accept the following:
116
+
-`filename` file name of the file being saved
117
+
118
+
-`layer_start`, `layer_end` and `layer_join` accept the following:
115
119
-`x` the last_x position before this layer, this is 0 for the first layer
116
120
-`y` the last_y position before this layer, this is 0 for the first layer
117
121
-`ix` the last integer x location before this layer, this is 0 for the first layer.
@@ -122,7 +126,8 @@ For example every element accepts the value of `index`. You would encode that in
122
126
-`layer_index1` the current layer number starting from 1
123
127
-`layer_id` as vpype layer ID.
124
128
-`filename` file name of the file being saved
125
-
-`line_start`, `line_end` and `line_join`: Accepts `x`, `y`, `ix`, `iy`, `index`, `index1`, `lines_index`, `lines_index1`, `layer_index`, `layer_index1`, `layer_id`, and `filename`.
129
+
130
+
-`line_start`, `line_end` and `line_join`accept the following:
126
131
-`x` the last_x position before this line, this is 0 for the first line of the first layer
127
132
-`y` the last_y position before this line, this is 0 for the first line of the first layer
128
133
-`ix` the last integer x location before this layer, this is 0 for the first layer.
@@ -136,36 +141,80 @@ For example every element accepts the value of `index`. You would encode that in
136
141
-`layer_id` values for the current vpype layer ID that contains this line
137
142
-`filename` file name of the file being saved
138
143
139
-
The segments (`segment_first`, `segment`, `segment_last`) accept a lot of values that may be useful statistics for various formats:
140
-
*`index`: index of the particular coordinate pair. eg `{index:d}`
141
-
*`x` absolute position x in floating point number. eg `{x:.4f}`
142
-
*`y` absolute position y in floating point number. eg `{y:g}`
143
-
*`dx` relative position x in floating point number. eg `{dx:f}`
144
-
*`dy` relative position y in floating point number. eg `{dy:.2f}`
145
-
*`_x` negated absolute position x in floating point number. eg `{_x:.4f}`
146
-
*`_y` negated absolute position y in floating point number. eg `{_y:g}`
147
-
*`_dx` negated relative position x in floating point number. eg `{_dx:f}`
148
-
*`_dy` negated relative position y in floating point number. eg `{_dy:.2f}`
149
-
*`ix` absolute position x in integer number. eg `{ix:d}`
150
-
*`iy` absolute position y in integer number. eg `{iy:d}`
151
-
*`idx` relative position x in integer number. eg `{idx:d}`
152
-
*`idy` relative position y in integer number. eg `{idy:d}`
153
-
*`index` same as `segment_index`
154
-
*`index1` same as `segment_index1`
155
-
*`segment_index` the current segment within this line starting from 0
156
-
*`segment_index1` the current segment within this line starting from 1
157
-
*`line_index` the current line index within this layer starting from 0
158
-
*`line_index1` the current line index within this layer number starting from 1
159
-
*`layer_index` the current layer index starting from 0
160
-
*`layer_index1` the current layer number starting from 1
161
-
*`layer_id` values for the current vpype layer ID that contains this line
162
-
*`filename` file name of the file being saved
144
+
-`segment_first`, `segment`, `segment_last` accept the following:
145
+
*`index`: index of the particular coordinate pair. eg `{index:d}`
146
+
*`x` absolute position x in floating point number. eg `{x:.4f}`
147
+
*`y` absolute position y in floating point number. eg `{y:g}`
148
+
*`dx` relative position x in floating point number. eg `{dx:f}`
149
+
*`dy` relative position y in floating point number. eg `{dy:.2f}`
150
+
*`_x` negated absolute position x in floating point number. eg `{_x:.4f}`
151
+
*`_y` negated absolute position y in floating point number. eg `{_y:g}`
152
+
*`_dx` negated relative position x in floating point number. eg `{_dx:f}`
153
+
*`_dy` negated relative position y in floating point number. eg `{_dy:.2f}`
154
+
*`ix` absolute position x in integer number. eg `{ix:d}`
155
+
*`iy` absolute position y in integer number. eg `{iy:d}`
156
+
*`idx` relative position x in integer number. eg `{idx:d}`
157
+
*`idy` relative position y in integer number. eg `{idy:d}`
158
+
*`index` same as `segment_index`
159
+
*`index1` same as `segment_index1`
160
+
*`segment_index` the current segment within this line starting from 0
161
+
*`segment_index1` the current segment within this line starting from 1
162
+
*`line_index` the current line index within this layer starting from 0
163
+
*`line_index1` the current line index within this layer number starting from 1
164
+
*`layer_index` the current layer index starting from 0
165
+
*`layer_index1` the current layer number starting from 1
166
+
*`layer_id` values for the current vpype layer ID that contains this line
167
+
*`filename` file name of the file being saved
163
168
164
169
#### Notes
165
170
*`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.
166
171
*`line_join` occurs after `line_end` but only appears *between* lines, it does not occur after the last line.
167
172
*`layer_join` occurs after `layer_end` but only appears *between* layers, it does not occur after the last layer.
168
173
174
+
### Using properties
175
+
176
+
In addition to the variables described in the previous section, any existing [property](https://vpype.readthedocs.io/en/latest/fundamentals.html#properties) may be used for substitution. For example, the layer color is stored as a property named `vp_color` and can be added to the profile with the pattern `{vp_color}`. Since this is a layer property, it would be available for all options but `document_start` and `document_end`, for which no current layer is defined. Global properties are available to all options.
177
+
178
+
There is no guarantee that a given property is defined upon export time, even system properties such as `vp_color`. If a property used in the selected profile doesn't exist, an error will be generated. To avoid this, a default value for the property must be provided, which can be achieved in two ways: in the config file or using the `--default` option.
179
+
180
+
This is an example of profile configuration which includes a default value for the `vp_color` and `vp_pen_width` properties:
0 commit comments