Created
March 5, 2023 21:13
-
-
Save remcoder/257f9d445d0588264faa7ae457adf241 to your computer and use it in GitHub Desktop.
convert gcode
This file contains hidden or 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
let prevGCmd = null; | |
const previewCode = gcode | |
.split('\n') | |
.map((i) => { | |
const line = i.trim(); | |
let result = line; | |
if (line.startsWith('G20')) { // keep as is | |
return result; | |
} | |
if (line.charAt(0) == 'G') { | |
const gCmd = new RegExp(/G\d+/g); | |
const matches = line.match(gCmd); | |
console.log(matches); | |
prevGCmd = matches[matches.length-1]; | |
// result = `G${line.slice(2)}`; | |
if (!line?.includes('Z')) { | |
result += ' E10'; | |
} | |
} | |
// else if (!line.includes('start') && ['X', 'Y'].includes(line.charAt(0))) { | |
// result = `G2 ${line} E10`; // this fails for G0/ G1 cmds: line 34/35 | |
// } | |
else if (['X', 'Y'].includes(line.charAt(0))) { | |
result = `${prevGCmd} ${line} E10`; | |
} | |
return result; | |
}) | |
.join('\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment