From 01750c190469248deafef4ff2de9d4dc9f2d1bf3 Mon Sep 17 00:00:00 2001 From: Slicingblade <60554216+Slicingblade@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:45:34 -0500 Subject: [PATCH 1/3] Create convertBatch.py Batch Process Binary to ASCII STL files --- convertBatch.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 convertBatch.py diff --git a/convertBatch.py b/convertBatch.py new file mode 100644 index 0000000..cec8862 --- /dev/null +++ b/convertBatch.py @@ -0,0 +1,60 @@ +# -*- encoding: utf-8 -*- +import struct +import csv +import sys +cycle = len(sys.argv) +if (cycle): + multipath = sys.argv +else: + sys.close() +print(cycle) + +for loop in range(1,cycle): + path= multipath[loop] + infile = open(path, 'rb') #import file + out = open(path + ' ASCII.stl', 'w') #export file + + data = infile.read() + + + out.write("solid ") + + for x in xrange(0,80): + if not ord(data[x]) == 0: + out.write(struct.unpack('c', data[x])[0]) + else: + pass + out.write("\n") + + number = data[80] + data[81] + data[82] + data[83] + faces = struct.unpack('I',number)[0] + + for x in range(0,faces): + out.write("facet normal ") + + xc = data[84+x*50] + data[85+x*50] + data[86+x*50] + data[87+x*50] + yc = data[88+x*50] + data[89+x*50] + data[90+x*50] + data[91+x*50] + zc = data[92+x*50] + data[93+x*50] + data[94+x*50] + data[95+x*50] + + out.write(str(struct.unpack('f',xc)[0]) + " ") + out.write(str(struct.unpack('f',yc)[0]) + " ") + out.write(str(struct.unpack('f',zc)[0]) + "\n") + + out.write("outer loop\n") + + for y in range(1,4): + out.write("vertex ") + + xc = data[84+y*12+x*50] + data[85+y*12+x*50] + data[86+y*12+x*50] + data[87+y*12+x*50] + yc = data[88+y*12+x*50] + data[89+y*12+x*50] + data[90+y*12+x*50] + data[91+y*12+x*50] + zc = data[92+y*12+x*50] + data[93+y*12+x*50] + data[94+y*12+x*50] + data[95+y*12+x*50] + + out.write(str(struct.unpack('f',xc)[0]) + " ") + out.write(str(struct.unpack('f',yc)[0]) + " ") + out.write(str(struct.unpack('f',zc)[0]) + "\n") + + out.write("endloop\n") + out.write("endfacet\n") + + out.close() + print path + " Proccessed \n" From 389abbc12347b0f757aacd1d1e35bb0a342caab6 Mon Sep 17 00:00:00 2001 From: Slicingblade <60554216+Slicingblade@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:10:11 -0500 Subject: [PATCH 2/3] Update convertBatch.py Fixed Error --- convertBatch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/convertBatch.py b/convertBatch.py index cec8862..d9ad71e 100644 --- a/convertBatch.py +++ b/convertBatch.py @@ -2,12 +2,13 @@ import struct import csv import sys -cycle = len(sys.argv) +cycle = len(sys.argv)-1 if (cycle): multipath = sys.argv else: - sys.close() -print(cycle) + print("No files passed \n Syntax convertbatch.py Filename1 ...") + sys.exit() + for loop in range(1,cycle): path= multipath[loop] From 01dff261fcd179bd562834e01b6a5ddf957f5fbc Mon Sep 17 00:00:00 2001 From: Slicingblade <60554216+Slicingblade@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:31:37 -0500 Subject: [PATCH 3/3] Update convertBatch.py Fixed Even more --- convertBatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convertBatch.py b/convertBatch.py index d9ad71e..fe7a5c0 100644 --- a/convertBatch.py +++ b/convertBatch.py @@ -10,8 +10,8 @@ sys.exit() -for loop in range(1,cycle): - path= multipath[loop] +for loop in range(0,cycle): + path= multipath[loop+1] infile = open(path, 'rb') #import file out = open(path + ' ASCII.stl', 'w') #export file