#!/bin/bash #this program is meant to produce a scaled cutting file directly from the GCode # original gcode from QCad or f-engrave filename is $1 # the scaled file is $2 # $3 is \#\\] exactly sed -r '1,$s/\sY/\*'$3' Y/' $1 > store1.ngc sed -r '1,$s/\sI/\*'$3' I/' store1.ngc > store2.ngc sed -r '1,$s/\sJ/\*'$3' J/' store2.ngc > store1.ngc sed -e '1,$s/[0-9][0-9]\.[0-9]*$/\*'$3'/' store1.ngc > store2.ngc sed -r '1,$s/X/X[/' store2.ngc > store1.ngc sed -r '1,$s/Y/Y[/' store1.ngc > store2.ngc sed -r '1,$s/I/I[/' store2.ngc > store1.ngc sed -r '1,$s/J/J[/' store1.ngc > store2.ngc tr '\r\n' 'q' < store2.ngc > store1.ngc sed -r 's/q/\*'$3' \n/'g < store1.ngc > store2.ngc #******* this code is good only for gcode output by qcad ******* #terminal command is bash $4 (loop counter depends on material thickness) $5 depth per pass (must be positive value) # original gcode from QCad filename is $1 # the cutall file is $2 # $4 is the loop counter # $5 is the cutting depth per pass sed 's/Z0.25/Z[#1]/' store2.ngc > store1.ngc sed 's/Z-0.125/Z[#2]/' store1.ngc > store2.ngc sed '/G94/ a\o100 sub' store2.ngc > store1.ngc sed "/M2/ i\o100 endsub\n#1 = 0.250 (clearance height for traveling) \ \n#2 = -0.0(initialize cutting depth) \ \n#5 = 1 (this is the pass counter and will increase with each execution of the while statement) \ \no101 while [#5 LE $4] (program loops $4 times) \ \n#2 = [#2 - $5] (lower z by $5 with each pass) \ \no100 call [#1] [#2] (notice #1 and #2 are passed as the parameters #1 and #2 to the subroutine) \ \n#5 = [#5 + 1] (increment the counter) \ \no101 endwhile" store1.ngc > store2.ngc # next statements remove Z axis scaling dependent on whether it is 1,2,3 decimals beyond the decimal point sed 's/Z\([0-9]\)\.\([0-9]\)\*'$3'/Z\1\.\2/g' store2.ngc > store1.ngc sed 's/Z\([0-9]\)\.\([0-9]\)\([0-9]\)\*'$3'/Z\1\.\2\3/g' store1.ngc > store2.ngc sed 's/Z\([0-9]\)\.\([0-9]\)\([0-9]\)\([0-9]\)\*'$3'/Z\1\.\2\3\4/g' store2.ngc > store1.ngc # next statement remove scaling from Z where parameters were passed sed 's/Z\(\[\#[0-9]\]\)\*'$3'/Z\1/g' store1.ngc > store2.ngc #next statement removes scaling after the F parameter sed 's/\(F[0-9][0-9]\)\*'$3'/\1/g' store2.ngc > store1.ngc #next statement removes scaling after M2 sed 's/M2\*'$3'/M2\1/g' store1.ngc > store2.ngc #next statement inserts # = 1 after the o100 sub command sed 'o100 sub\n/o100 sub\n\n"# = 1"' store2.ngc > $2 #remove temporary files if [ -f store1.ngc ] then rm store1.ngc fi if [ -f store2.ngc ] then rm store2.ngc fi #ta@ta-Precision-WorkStation-T7400:~/Desktop/CNC/Router/sed$ bash Scale_cutall_combined.sh test.txt test1.txt \#\\] 2 .250 # $1 $2 $3 $4 $5 #still to do-