Improving your Laser Workflow
Improving your Laser Workflow

After writing a few scripts to make 3D printing easier for me, I decided to apply the same principle to my laser cutter workflow (where vectors are drawn in Inkscape, exported using the gcodetools extension, then cleaned up by scripts):

# args_to_json.py
import argparse, json
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--power', default=200,
		help='spindle speed, 0-1000', type=int)
parser.add_argument('-s', '--speed', default=1200,
		help='movement velocity, 70-2000', type=int)
parser.add_argument('-n', '--number_files', default=1,
		help='number of recent files to grab', type=int)
parser.add_argument('-r', '--repeat', default=1,
		help='number of passes to make of each file', type=int)
parser.add_argument('name',
		help='basename of output file')
args = parser.parse_args()

print(json.dumps(args.__dict__))
# quick-convert.bash
# Grabs the most recently created files from gcodetools and calls
# 'gcodetools_to_FSE_laser.sh' and 'concatenate_gcode' in one shot
set -e
CONFIG=quick-convert.json
NGC_DIR="$(dirname ~)/$(basename ~)/ngc"
DIR=$(dirname $0)
ARGS="$DIR/args_to_json.py"
CONVERT="$DIR/gcodetools_to_FSE_laser.sh"
CAT="$DIR/concatenate_gcode.sh"

function echo_stderr
{
	echo "$1" 1>&2
}

# get user config from command line
python "$ARGS" "$@" > $CONFIG

function getcfg
{
	sed -e s/\ //g -e s/{//g -e s/}//g $CONFIG | tr ,: "\n" | grep $1 -A 1 | sed -n 2p
}

NAME=$(getcfg name | sed s/\"//g)
POWER=$(getcfg power)
SPEED=$(getcfg speed)
NUM=$(getcfg number_files)
REPEAT=$(getcfg repeat)
OUTPUT="$NGC_DIR/$NAME"'_p'"$POWER"'_s'"$SPEED"'_x'"$REPEAT"'.ngc'
REMOTE="server:/path/to/dir/"
FILES=( $(ls $NGC_DIR/ | grep output_[0-9][0-9][0-9][0-9].ngc | tail -n $NUM) )

# convert all input files
for i in $(seq $NUM); do
	FILE="$NGC_DIR/"${FILES[$i-1]}
	# if file doesn't exist
	if [ -z $FILE ]; then
		exit 1
	fi
	echo_stderr "$CONVERT $FILE $POWER $SPEED > $i.ngc"
	$CONVERT $FILE $POWER $SPEED > $i.ngc
done

# concatenate files
CAT_OPTS=""
for i in $(seq $NUM); do
	FILE=$i.ngc
	for j in $(seq $REPEAT); do
		CAT_OPTS+="$i.ngc "
	done
done
echo_stderr "$CAT $CAT_OPTS > $OUTPUT"
$CAT "$CAT_OPTS" > "$OUTPUT"

# copy to shared folder
SCP="scp $OUTPUT $REMOTE"
echo_stderr "$SCP"
$SCP

# remove temp files
RM_OPTS=""
for i in $(seq $NUM); do
	RM_OPTS+="$i.ngc "
done
echo_stderr "rm $RM_OPTS"
rm $RM_OPTS
rm $CONFIG

The end result is a quicker draw/laser-cut cycle for my most common use case. More complicated cuts still require me to use the original scripts… it’s amazing they work so well after so much time!


Leave a Comment?

Send me an email, then I'll place our discussion on this page (with your permission).


Return | About/Contact