Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dmerand
Last active June 19, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmerand/43250c688d73f6b589ae7ed13bb1ce7d to your computer and use it in GitHub Desktop.
Save dmerand/43250c688d73f6b589ae7ed13bb1ce7d to your computer and use it in GitHub Desktop.
Insert a pause into a GCODE <<file>> at <<layer number>>, matching layers against an optional <<regex>>
#!/usr/bin/env sh
#---------------------------------------------------------#
# gcode_pause
# Donald L. Merand
# ----------------
# Given (1) a file, (2) a layer number, and an optional
# (3) regular expression matching layer change, add a
# pause command (defaults to "M226" but changeable) to
# the GCODE.
#---------------------------------------------------------#
# if your printer firmware does something different to pause, eg M0,
# vvvvvv change this
PAUSE_CMD="M226"
# "parse" input params
FILENAME="$1"
shift
LAYER="$1"
shift
if [ "$1" ]; then
REGEX="$1"
else
# if you don't use Simplify3D, you might want to change...
# vvvvvvvvvvvvvvvvv default layer change code in Simplify3D.
REGEX="; layer ${LAYER},"
fi
# test for legit params
if [ -z "${FILENAME}" -o -z "${LAYER}" ]; then
echo "USAGE: gcode_pause <<FILENAME>> <<LAYER_NUMBER_TO_PAUSE>> {LAYER_REGEX}"
exit 1
fi
# otherwise insert layer pause code
cat "${FILENAME}" |
awk "/${REGEX}/{print \"; USER-ADDED PAUSE\n${PAUSE_CMD}\"}{print \$0}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment