# CNFR33D v 0.5 # A Free CNC GCode converter for 3D CNC Files # Created By Peter Kenna 2016 targetFileName = raw_input("Please enter file name: ") targetFile = open(targetFileName+".gcode", 'r') newFileName = targetFileName+"_CNF33D.gcode" newFile = open(newFileName, 'w') currentZ = "Z0.0" startChanges = False for line in targetFile: fastMove = line.find("G0 ") zMove = line.find("Z") if startChanges == False: # Don't invert Z Moves until routing starts newFile.write(line) # Add the line to the new file as-is if line.find("M117"): startChanges = True if startChanges == True: # Start inverting Z Moves if fastMove == -1: # If it's not a fast move newFile.write(line) # Add the line to the new file as-is if fastMove != -1 and zMove == -1: # If it's a fast move, but not a Z move newFile.write("G0 Z0.0\n") # Raise the bit before moving to avoid hitting uncut sections newFile.write(newLine) # Move to a new section newFile.write("G0 "+currentZ) # Lower the bit back to the correct height if fastMove != -1 and zMove != -1: # If it's a fast move and a Z move newLine = "" prevLetter = "" newZ = "" startZ = False for letter in line: if letter != "Z" and prevLetter != "G": # If it's not something we're changing newLine = newLine+letter # Add it to the new line as-is if startZ: newZ = newZ+letter if letter == "Z": # If its a Z move newLine = newLine+"Z-" # Invert it startZ = True newZ = "Z-" if prevLetter == "G" and letter == "0": # If this is a fast move newLine = newLine+"1" # make it a normal move prevLetter = letter currentZ = newZ newFile.write(newLine) targetFile.close newFile.close