Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- # Set the path to your G-code file
- gcode_file_path = 'path/to/gcode/file.gcode'
- # Set the path to the OpenSCAD script that generates the SVG
- openscad_script_path = 'path/to/openscad/script.scad'
- # 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, convert it to an SVG
- if layer_number is not None:
- # Construct the output file name
- output_file_name = f'layer_{layer_number}.svg'
- # Join the layer's G-code lines into a single string
- layer_code = ''.join(layer_lines)
- # Create the OpenSCAD command to generate the SVG
- openscad_command = f'openscad -o {output_file_name} -D "gcode=\'{layer_code}\'" {openscad_script_path}'
- # Run the OpenSCAD command
- subprocess.run(openscad_command, shell=True)
- # 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, convert it to an SVG
- if layer_number is not None:
- # Construct the output file name
- output_file_name = f'layer_{layer_number}.svg'
- # Join the layer's G-code lines into a single string
- layer_code = ''.join(layer_lines)
- # Create the OpenSCAD command to generate the SVG
- openscad_command = f'openscad -o {output_file_name} -D "gcode=\'{layer_code}\'" {openscad_script_path}'
- # Run the OpenSCAD command
- subprocess.run(openscad_command, shell=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement