Categories
goatee-stroking musing, or something

memo to self: trivial HP-GL → GCode converter

an outlined lozenge with the work "Phween!" in italcis in teh centre. The text is hatched diagonally.
what the sample files render

Updated: here’s a better one. Who knew that hp2xx had a gcode mode built in?

hp2xx -t -m nc -z 0 -Z 5 -f - file.hpgl | grep -v '^M0.' | sed 's/^G01/G0/;' | awk 'BEGIN {print "G21\nG90";} END {print "G0 Z5";} {print;}' > file.gcode

Aah, no: forget the stuff below.

hp2xx -t -m hpgl -f - phweeen.hpgl | sed 's/;/\n/g;' | grep -v '^SP' | grep -v PA | awk -F, 'BEGIN {print "G0X0Y0Z5";} /^PU/ {sub(/PU/, "", $1); printf("G0Z5\nG0X%fY%f\n", $1/40.0, $2/40.0);} /^PD/ {sub(/PD/, "", $1); printf("G0Z0\nG0X%fY%fZ0\n", $1/40.0, $2/40.0);} END {print "G0Z5";}' > ~/Desktop/phweeen.gcode
  1. likely targets a MidTBot a little too much
  2. ignores pen changes
  3. assumes pen up means tool Z=5 and pen down means tool Z=0
  4. only understands PU (move) and PD (draw) commands
  5. requires hp2xx
  6. tested with trivially few sample files exported as HP-GL from Inkscape
  7. doesn’t care about paper size; your plotter does, though.

Leave a Reply

Your email address will not be published. Required fields are marked *