-
Notifications
You must be signed in to change notification settings - Fork 39
Script pygcode crop
This script cuts out a portion of a gcode file so it may be executed independently of the rest of the file.
usage: pygcode-crop [-h] infile range
Remove gcode before and after given 'from' and 'to' conditions.
positional arguments:
infile gcode file to crop
range file range to crop, format [from]:[to] (details below)
optional arguments:
-h, --help show this help message and exit
Range Format:
range must be of the format:
[condition[,condition...]]:[condition[,condition...]]
the first condition(s) are true for the first line included in the cropped area
the second set are true for the first line excluded after the cropped area
Conditions:
each condition is of the format:
{variable}{operation}{number}
or, more specifically:
[[{a,b,c,n,x,y,z}]{=,!=,<,<=,>,>=}]{number}
Condition Variables:
n - file's line number
a|b|c - machine's angular axes
x|y|z - machine's linear axes
Example Ranges:
"100:200" will crop lines 100-199 (inclusive)
"z<=-2:" will isolate everything after the machine crosses z=-2
"x>10,y>10:n>=123" starts cropped area where both x and y exceed 10,
but only before line 123
Limitations:
Only takes points from start and finish of a gcode operation, so a line
through a condition region, or an arc that crosses a barrier will NOT
trigger the start or stop of cropping.
Probe alignment operations will not change virtual machine's position.
Cut specific lines
cut out from line 100 to line 199 (inclusive) of the part.gcode
file (yielding 100 lines)
$ pygcode-crop part.gcode 100:200
note: 200
is the first line excluded from the cropped region
also: the above line is equivalent to:
$ pygcode-crop part.gcode =100:=200
$ pygcode-crop part.gcode n=100:n=200
where n
is the file's line number
Resume from depth
Let's say you have a pocket operation, but you had to stop it half way through (at a depth of 3.2mm). you can resume it by cropping out everything before Z reached -3.2mm
$ pygcode-crop pocket.gcode "z<=-3.2:"
note: as soon as <
or >
characters are used in the conditions, the range
parameter must be expressed inside "
quotes.
Only middle part
Or you're engraving 3 words stacked on top of each other, but you only want to engrave the middle word.
The space between the top 2 words centres at y=3mm
, and between the bottom 2 words is at y=6mm
.
$ pygcode-crop engraving.gcode "y>3:y>6"
Multiple Conditions
You can also separate multiple conditions with ,
s, they're all and
ed together.
So in the engraving example, if you have 2 sets of 3 words:
Jane foo
loves bar
John roo
engraved in the order Jane
, loves
, John
, foo
, bar
, and lastly roo
. And the blank region in between engravings centres around x~=10
to just engrave bar
you can crop it out with:
$ pygcode-crop engraving.gcode "x>10,y>3:y>6"
Usage
Commands
Information