DrLex0 / FFCP-GCodeSnippets

G-Code and scripts for using the FlashForge Creator Pro with PrusaSlicer (Slic3r)
https://www.dr-lex.be/software/ffcp-slic3r-profiles.html?r=gh
Creative Commons Attribution 4.0 International
58 stars 16 forks source link

Number regex doesn't work in get_highest_z() #2

Closed sej7278 closed 5 years ago

sej7278 commented 5 years ago

make_fcp_x3g wrapper script seems to use \d instead of [0-9] for digits which errors with:

WARNING: could not find highest Z coordinate. If this is a valid G-code file, the make_fcp_x3g script needs updating.

The fix is (PR seemed like overkill):

diff --git a/make_fcp_x3g b/make_fcp_x3g
index 108d41a..6bc219e 100755
--- a/make_fcp_x3g
+++ b/make_fcp_x3g
@@ -267,7 +267,7 @@ function get_highest_z
        # Extract highest Z value in a G1 command from the last 2048 lines of a file.
        local gcode=$1

-       tail -n 2048 "${gcode}" | grep -oE '^G1 [^;]*Z\d*\.?\d+' | \
+       tail -n 2048 "${gcode}" | grep -oE '^G1 [^;]*Z[0-9]*\.?[0-9]+' | \
            awk '{print $2}' | cut -b 2- | sort -g | tail -n 1
 }
DrLex0 commented 5 years ago

Thanks for catching this. It seems this is a difference between the OS X version of grep (recognizes \d) and the one in Linux (doesn't).

Cool, GitHub has auto-closed this after I pushed my commit…

sej7278 commented 5 years ago

yeah i've seen the osx vs linux thing before - you get the same problem with sed too.