diff --git a/TOOLS/check_mesh.py b/TOOLS/check_mesh.py old mode 100644 new mode 100755 index df333c1..f68bdd9 --- a/TOOLS/check_mesh.py +++ b/TOOLS/check_mesh.py @@ -1,38 +1,52 @@ -import sys import re +import os -# grid size -grid_size = 7 - -input_file = 'printer_max.cfg' output_file = 'mesh.txt' +input_file = 'printer_max.cfg' -# Check if --grid is defined -if '--grid' in sys.argv: - # If --grid is defined, then set the grid size to specified value - grid_size = int(sys.argv[sys.argv.index('--grid') + 1]) +if __name__ == "__main__": -# Open the input file -with open(input_file, 'r') as f: - # Read the file - data = f.read() + # Detect anything with printer*.cfg + for file in os.listdir('.'): + # Check if the filename contains printer and cfg + if "printer" in file and ".cfg" in file: + input_file = file + break - # Extract points values from: [besh_profile_default] - mesh_raw = re.search(r'\[besh_profile_default\]\nversion : 1\npoints : (.+?)\n', data, re.DOTALL).group(1) + # Open the input file + with open(input_file, 'r') as f: + # Read the file + data = f.read() - # Split by comma into a array + # Extract points values from: [besh_profile_default] + mesh_raw = re.search(r'\[besh_profile_default\]\nversion : 1\npoints : (.+?)\n', data, re.DOTALL).group(1) - mesh_array = mesh_raw.split(', ') + # Split by comma into a array - # Take all points up to the grid size. 7 values then put them into a new array and repeat until there are no more points - mesh = [mesh_array[i:i + grid_size] for i in range(0, len(mesh_array), grid_size)] + mesh_array = mesh_raw.split(', ') - for i in range(grid_size): - print(i, end=' ') - print() - for i in range(grid_size): - # print(f'{i} {mesh[i]}') - # Unstructure the array - print(f'{i} {" ".join(mesh[i])}') + # Ask for the grid size + grid_size = str(input("Enter the grid size. Example: 7x7: ")) + + try: + grid_x = int(grid_size.split('x')[0]) + grid_y = int(grid_size.split('x')[1]) + except: + print("Invalid grid size") + exit(1) + + + # Take all points up to the grid size. 7 values then put them into a new array and repeat until there are no more points + # mesh = [mesh_array[i:i+grid_size] for i in range(0, len(mesh_array), grid_size)] + # Use x and y + mesh = [mesh_array[i:i+grid_x] for i in range(0, len(mesh_array), grid_y)] + + mesh_str = "" + mesh_str += "\n" + for i in range(len(mesh)): + mesh_str += f"{i} {' '.join(map(str, mesh[i]))}\n" + + # Print the result + print(mesh_str) \ No newline at end of file