Created
November 1, 2020 21:29
-
-
Save nmaggioni/92867e84cc798ee921345a519714ac1a to your computer and use it in GitHub Desktop.
Get the max/avg XYZ dimensions of a bunch of GCODE files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Inspired by @leadgtr7 (https://github.com/buildbotics/bbctrl-firmware/issues/235#issuecomment-580387955) | |
import glob | |
def average(lst): | |
return sum(lst) / len(lst) | |
maxes = {'X': [], 'Y': [], 'Z': []} | |
for f in glob.glob('./*.gcode'): | |
with open(f, 'r') as gcode: | |
localMaxes = {'X': 0, 'Y': 0, 'Z': 0} | |
for line in gcode: | |
if line[0] == "G": | |
lineText = list( | |
filter(lambda x: x != '', line.replace("\n", "").strip().split(" "))) | |
if len(lineText) > 1: | |
for i in lineText: | |
if i[0] == ';': | |
break | |
for axis in maxes.keys(): | |
if i[0] == axis: | |
if float(i[1:]) > localMaxes[axis]: | |
localMaxes[axis] = float(i[1:]) | |
print("{}: {}".format(f, localMaxes)) | |
for axis in maxes.keys(): | |
maxes[axis].append(localMaxes[axis]) | |
print("\nMaximum print size: {:.2f} x {:.2f} x {:.2f} mm".format(max(maxes['X']), max(maxes['Y']), max(maxes['Z']))) | |
print("Average print size: {:.2f} x {:.2f} x {:.2f} mm".format(average(maxes['X']), average(maxes['Y']), average(maxes['Z']))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment