Last active
March 5, 2023 21:24
-
-
Save remcoder/2c99e809124d377e7e3f205accbcbbb2 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.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