Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set the path to your G-code file
- gcode_file_path = 'path/to/gcode/file.gcode'
- # Open the G-code file for reading
- with open(gcode_file_path, 'r') as gcode_file:
- # Initialize variables for tracking layer information
- layer_number = None
- layer_lines = []
- # Loop through each line in the file
- for line in gcode_file:
- # Check if the line contains a layer number
- if line.startswith(';LAYER:'):
- # If we have previous layer data, save it to a file
- if layer_number is not None:
- # Construct the output file name
- output_file_name = f'layer_{layer_number}.gcode'
- # Open the output file for writing
- with open(output_file_name, 'w') as output_file:
- # Write the layer's G-code to the output file
- output_file.writelines(layer_lines)
- # Clear the layer data for the next iteration
- layer_number = None
- layer_lines = []
- # Parse the layer number from the line
- layer_number = int(line.split(':')[1])
- # Add the line to the current layer's data
- layer_lines.append(line)
- # If there is still layer data remaining after the loop, save it to a file
- if layer_number is not None:
- # Construct the output file name
- output_file_name = f'layer_{layer_number}.gcode'
- # Open the output file for writing
- with open(output_file_name, 'w') as output_file:
- # Write the layer's G-code to the output file
- output_file.writelines(layer_lines)
Add Comment
Please, Sign In to add comment