Skip to content

Instantly share code, notes, and snippets.

@Arsey
Created November 25, 2014 19:28
Show Gist options
  • Save Arsey/a8721ae65530bd66998e to your computer and use it in GitHub Desktop.
Save Arsey/a8721ae65530bd66998e to your computer and use it in GitHub Desktop.
start print from Z layer
<?php
$reading = fopen('1.gcode', 'r');
$writing = fopen('1.tmp', 'w');
$replaced = false;
$i = 0;
echo '<pre>';
while (!feof($reading)) {
$i++;
$line = fgets($reading);
preg_match_all('/(G.*F.*\sZ(\d+(?:\.[0-9]{1,2})?))/', $line, $matches);
if ($matches[0]) {
$line = str_replace($matches[2][0], round(($matches[2][0] - 33.48) . '0',3), $line);
$replaced = true;
}
fputs($writing, $line);
}
fclose($reading);
fclose($writing);
// might as well not overwrite the file if we didn't replace anything
if ($replaced) {
rename('1.tmp', 'gcode');
} else {
unlink('1.tmp');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment