Created
July 24, 2019 13:08
-
-
Save urish/c0b05a0d2de4d06b771045125bcb4fc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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