Skip to content

Instantly share code, notes, and snippets.

@remcoder
Last active March 5, 2023 21:24
Show Gist options
  • Save remcoder/2c99e809124d377e7e3f205accbcbbb2 to your computer and use it in GitHub Desktop.
Save remcoder/2c99e809124d377e7e3f205accbcbbb2 to your computer and use it in GitHub Desktop.
convert gcode
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