Created
November 25, 2014 19:28
-
-
Save Arsey/a8721ae65530bd66998e to your computer and use it in GitHub Desktop.
start print from Z layer
This file contains 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
<?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