Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Note: This script should go last since the input file is renamed
- import sys
- import re
- import os
- parmEstimatedHours = ''
- parmEstimatedMinutes = ''
- parmEstimatedSeconds = ''
- parmFilamentType = ''
- parmLayerHeight = ''
- parmNozzleDiameter = ''
- parm1stLayerTemperature = ''
- parm1stLayerBedTemperature = ''
- parmTemperature = ''
- parmBedTemperature = ''
- parmNotes = ''
- sourceFile=sys.argv[1]
- # Read the ENTIRE g-code file into memory
- with open(sourceFile, "r") as f:
- lines = f.readlines()
- # Parse gcode lines for print information
- for line in lines:
- # currLine += 1
- # parts = line.split(';', 1)
- # if len(parts) > 0:
- # # Split line into command and comments
- # command = parts[0].strip()
- # if len(parts) > 1:
- # # Parse comments
- # comment = parts[1].strip()
- stringMatch = re.search ('; notes = (.*)', line)
- if stringMatch:
- parmNotes = stringMatch.group(1).strip()
- print(parmNotes)
- stringMatch = re.search('estimated printing time \(normal mode\) =.* ([0-9]+)h.*', line)
- if stringMatch:
- parmEstimatedHours = stringMatch.group(1)+'h'
- print(parmEstimatedHours)
- stringMatch = re.search('estimated printing time \(normal mode\) =.* ([0-9]+)m.*', line)
- if stringMatch:
- parmEstimatedMinutes = stringMatch.group(1)+'m'
- stringMatch = re.search('estimated printing time \(normal mode\) =.* ([0-9]+)s.*', line)
- if stringMatch:
- parmEstimatedSeconds = stringMatch.group(1)+'s'
- # Parse print job parameters
- stringMatch = re.search('filament_type = (.*)', line)
- if stringMatch:
- parmFilamentType = stringMatch.group(1)
- stringMatch = re.search('nozzle_diameter = (.*)', line)
- if stringMatch:
- parmNozzleDiameter = stringMatch.group(1)
- stringMatch = re.search('layer_height = (.*)', line)
- if stringMatch:
- parmLayerHeight = stringMatch.group(1)
- # Parse temperatures
- stringMatch = re.search('bed_temperature = (.*)', line)
- if stringMatch:
- parmBedTemperature = stringMatch.group(1)
- stringMatch = re.search('first_layer_bed_temperature = (.*)', line)
- if stringMatch:
- parm1stLayerBedTemperature = stringMatch.group(1)
- stringMatch = re.search('temperature = (.*)', line)
- if stringMatch:
- parmTemperature = stringMatch.group(1)
- stringMatch = re.search('first_layer_temperature = (.*)', line)
- if stringMatch:
- parm1stLayerTemperature = stringMatch.group(1)
- destFile = re.sub('\.gcode$','',sourceFile)
- #os.rename(sourceFile,destFile + '.filename.bak')
- print('Destination file is %s' % re.sub('.*/','',destFile))
- if parmNotes:
- destFile = destFile + ' ('+parmNotes+')'
- if parmFilamentType:
- destFile = destFile + ' '+parmFilamentType
- if parmLayerHeight:
- destFile = destFile + ' '+parmLayerHeight
- if parmNozzleDiameter:
- destFile = destFile + 'X'+parmNozzleDiameter
- if parm1stLayerTemperature:
- destFile = destFile + ' '+parm1stLayerTemperature
- if parmTemperature:
- destFile = destFile + '-'+parmTemperature
- if parm1stLayerBedTemperature:
- destFile = destFile + ' '+parm1stLayerBedTemperature
- if parmBedTemperature:
- destFile = destFile + '-'+parmBedTemperature
- if parmEstimatedHours or parmEstimatedMinutes or parmEstimatedSeconds:
- destFile = destFile + ' '
- if parmEstimatedHours:
- destFile = destFile + parmEstimatedHours
- if parmEstimatedMinutes:
- destFile = destFile + parmEstimatedMinutes
- if parmEstimatedSeconds:
- destFile = destFile + parmEstimatedSeconds
- destFile = destFile + '.gcode'
- print('Writing to %s' % re.sub('.*/','',destFile))
- with open(destFile, "w") as of:
- for lIndex in xrange(len(lines)):
- oline = lines[lIndex]
- of.write(oline)
- of.close()
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement