Skip to content

Instantly share code, notes, and snippets.

@dmerand dmerand/gcode_pause.sh
Last active Jun 19, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.