Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import re
PAINT_X = 172
PAINT_Y = 92
PAINT_Z = 40.5
MOVEOVER_Z = 55
SHAKE_RADIUS = 1
f = open('dna_pattern.gcode', 'r')
output = open('dna_output.gcode', 'w')
output.write('; Home\nG28\n')
for line in f:
line = line.strip()
if line[0:1] == '(':
output.write('; ' + re.sub(r'^\s*\(|\)\s*$', '', line) + '\n')
if line == '(Change tool to Default tool)':
output.write('G0 F3000 Z%f\n' % MOVEOVER_Z)
output.write('G0 X%f Y%f\n' % (PAINT_X, PAINT_Y))
output.write('G0 Z%f\n' % PAINT_Z)
output.write('; Shake\n')
for i in range(10):
output.write('G0 X%f Y%f\n' % (PAINT_X - SHAKE_RADIUS, PAINT_Y - SHAKE_RADIUS))
output.write('G0 X%f Y%f\n' % (PAINT_X + SHAKE_RADIUS, PAINT_Y - SHAKE_RADIUS))
output.write('G0 X%f Y%f\n' % (PAINT_X + SHAKE_RADIUS, PAINT_Y + SHAKE_RADIUS))
output.write('G0 X%f Y%f\n' % (PAINT_X - SHAKE_RADIUS, PAINT_Y + PAINT_RADIUS))
output.write('G0 F1000 Z55\n')
if line[0:2] == 'G0':
cmd = re.sub(r'\([^\)]*\)', '', line[3:])
output.write(line[0:2] + ' F1000' + cmd + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment