Created
June 1, 2020 08:09
-
-
Save CapnKernel/7f1aa0cd3044235b44c011c6728f8071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/gawk -f | |
BEGIN { | |
NOZZLE="S0"; | |
BED="S0"; | |
SKIP=0; | |
LN=0; | |
INCLUDE=0; | |
LASTZ=""; | |
} | |
NR == -1 { | |
SKIP=1; | |
} | |
match($0, /.*(; Move to start position)/, a) { | |
$0 = "G1 X0.1 Y15 Z0.3 F5000.0 " a[1]; | |
} | |
match($0, /.*(; Draw the first line)/, a) { | |
$0 = "G1 X200 Y15 Z0.3 F1500.0 E15 " a[1]; | |
} | |
match($0, /.*(; Move to side a little)/, a) { | |
$0 = "G1 X200 Y15.3 Z0.3 F5000.0 " a[1]; | |
} | |
match($0, /.*(; Draw the second line)/, a) { | |
$0 = "G1 X0.1 Y15.3 Z0.3 F1500.0 E30 " a[1]; | |
} | |
#match($0, /.*(; Move Z Axis up little to prevent scratching of Heat Bed)/, a) { | |
# $0 = ";" a[0]; | |
#} | |
match($0, /.*(; Move over to prevent blob squish)/, a) { | |
$0 = "; " a[0]; | |
} | |
match($0, /^M(140|104) (S[0-9]+)/, a) { | |
# BED1="2"; | |
if (a[2] != "S0") { | |
# print $0 " A1=" a[1] " A2=" a[2] | |
if (a[1] == "104") { | |
NOZZLE=a[2]; | |
# print "NOZZLE=" NOZZLE; | |
} | |
if (a[1] == "140") { | |
BED=a[2]; | |
# print "BED=" BED; | |
} | |
} | |
} | |
/;LAYER:0/ { | |
SKIP=1; | |
INCLUDE=1; | |
} | |
L && match($0, "^;LAYER:" L "$", a) { | |
SKIP=0; | |
} | |
# Include these codes even when skipping | |
match($0, /^M(106|107|140)/, a) { | |
INCLUDE=1 | |
} | |
# Find a Z-changing command in the skipped part (will end up being most recent Z) | |
SKIP == 1 && match($0, / Z[0-9]/, a) { | |
LASTXY="" | |
for(i=2; i<=NF; i++) { | |
CMD=substr($i, 1, 1); | |
if (CMD == "F") | |
LASTF = $i; | |
else if (CMD == "Z") | |
LASTZ = $i; | |
else { | |
LASTXY = LASTXY " " $i; | |
# print("CMD=" CMD " $i=" $i); | |
} | |
} | |
# print "LASTF=" LASTF " LASTZ=" LASTZ " LASTXY=" LASTXY; | |
} | |
SKIP == 0 || INCLUDE == 1 { | |
LINES[LN++]=$0; | |
INCLUDE=0; | |
} | |
END { | |
# print "BED=" BED; | |
# print "NOZZLE=" NOZZLE; | |
# print "LN=" LN; | |
for (NR=0; NR < LN; NR++) { | |
$0 = LINES[NR]; | |
if (match($0, /^M(140|104|190|109) (S[0-9]+)(.*)/, a)) { | |
# print "@@@ a2=" a[2]; | |
if (a[2] != "S0") { | |
if (a[1] == "104" || a[1] == "109") { | |
$0 = "M" a[1] " " NOZZLE a[3]; | |
} | |
if (a[1] == "140" || a[1] == "190") { | |
$0 = "M" a[1] " " BED a[3]; | |
} | |
} | |
} | |
if (match($0, /;LAYER:([0-9]+)/, a)) { | |
if (a[1] == L) { | |
match(LASTZ, /Z(.*)/, a); | |
# print "@@@ a1=" a[1]; | |
Z1 = a[1] + 1; | |
Z10 = a[1] + 10; | |
print("G0 " LASTF " Z" Z10); | |
print("M0 M0"); | |
print("G0 " LASTF LASTXY); | |
print("M0 M1"); | |
print("G0 " LASTZ1); | |
print("G1 F2700 E4.8") | |
print("M0 M1"); | |
print("G0 " LASTZ); | |
print("M0 M2"); | |
} | |
} | |
print; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment