mirror of
https://github.com/nophead/Mendel90.git
synced 2025-08-20 03:51:20 +02:00
Mods to python scripts to allow boms and stls for accessories to be made.
This commit is contained in:
52
accessories.py
Normal file
52
accessories.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import bom
|
||||
import stls
|
||||
import shutil
|
||||
import os
|
||||
|
||||
def accessories(machine, assembly = None):
|
||||
assemblies = ["raspberry_pi_assembly", "raspberry_pi_camera_assembly", "light_strip_assembly" ]
|
||||
|
||||
#
|
||||
# Make the target directory
|
||||
#
|
||||
target_dir = machine + "/stls/accessories"
|
||||
if os.path.isdir(target_dir):
|
||||
if not assembly:
|
||||
shutil.rmtree(target_dir) #if making all of them clear the directory first
|
||||
os.makedirs(target_dir)
|
||||
else:
|
||||
os.makedirs(target_dir)
|
||||
|
||||
|
||||
if assembly:
|
||||
assemblies = [ assembly ]
|
||||
for assembly in assemblies:
|
||||
print(assembly)
|
||||
bom.boms(machine, assembly)
|
||||
stl_list = stls.bom_to_stls(machine, assembly)
|
||||
stls.stls(machine, stl_list)
|
||||
#
|
||||
# Move all the stls that are not in the plates to the plates directory
|
||||
#
|
||||
for file in stl_list:
|
||||
src = machine + "/stls/"+ file
|
||||
if os.path.isfile(src):
|
||||
shutil.move(src, target_dir + "/" + file)
|
||||
else:
|
||||
print("can't find %s to move" % src)
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = len(sys.argv)
|
||||
if args > 1:
|
||||
if args > 2:
|
||||
accessories(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
accessories(sys.argv[1])
|
||||
else:
|
||||
print("usage: accessories mendel|sturdy|your_machine [assembly_name]")
|
||||
sys.exit(1)
|
65
bom.py
65
bom.py
@@ -7,6 +7,23 @@ import sys
|
||||
import shutil
|
||||
import openscad
|
||||
|
||||
source_dir = "scad"
|
||||
|
||||
def find_scad_file(assembly):
|
||||
for filename in os.listdir(source_dir):
|
||||
if filename[-5:] == ".scad":
|
||||
#
|
||||
# look for module which makes the assembly
|
||||
#
|
||||
for line in open(source_dir + "/" + filename, "r").readlines():
|
||||
words = line.split()
|
||||
if len(words) and words[0] == "module":
|
||||
module = words[1].split('(')[0]
|
||||
if module == assembly:
|
||||
return filename
|
||||
|
||||
|
||||
return None
|
||||
|
||||
class BOM:
|
||||
def __init__(self):
|
||||
@@ -86,17 +103,40 @@ class BOM:
|
||||
for ass in sorted(self.assemblies):
|
||||
print("%3d %s" % (self.assemblies[ass].count, self.assemblies[ass].make_name(ass)), file=file)
|
||||
|
||||
def boms(machine):
|
||||
def boms(machine, assembly = None):
|
||||
|
||||
bom_dir = machine + "/bom"
|
||||
if os.path.isdir(bom_dir):
|
||||
shutil.rmtree(bom_dir)
|
||||
os.makedirs(bom_dir)
|
||||
if assembly:
|
||||
bom_dir += "/accessories"
|
||||
if not os.path.isdir(bom_dir):
|
||||
os.makedirs(bom_dir)
|
||||
else:
|
||||
assembly = "machine_assembly"
|
||||
if os.path.isdir(bom_dir):
|
||||
shutil.rmtree(bom_dir)
|
||||
os.makedirs(bom_dir)
|
||||
|
||||
f = open("scad/conf/machine.scad","wt")
|
||||
f. write("include <%s_config.scad>\n" % machine);
|
||||
f.close()
|
||||
|
||||
openscad.run("-D","$bom=2","-o", "dummy.csg", "scad/bom.scad")
|
||||
#
|
||||
# Find the scad file that makes the module
|
||||
#
|
||||
scad_file = find_scad_file(assembly)
|
||||
if not scad_file:
|
||||
raise Exception("can't find source for " + assembly)
|
||||
#
|
||||
# make a file to use the module
|
||||
#
|
||||
bom_maker_name = source_dir + "/bom.scad"
|
||||
f = open(bom_maker_name, "w")
|
||||
f.write("use <%s>\n" % scad_file)
|
||||
f.write("%s();\n" % assembly);
|
||||
f.close()
|
||||
#
|
||||
# Run openscad
|
||||
#
|
||||
openscad.run("-D","$bom=2","-o", "dummy.csg", bom_maker_name)
|
||||
print("Generating bom ...", end=" ")
|
||||
|
||||
main = BOM()
|
||||
@@ -122,7 +162,8 @@ def boms(machine):
|
||||
if stack:
|
||||
main.assemblies[stack[-1]].add_part(s)
|
||||
|
||||
main.print_bom(True, open(bom_dir + "/bom.txt","wt"))
|
||||
if assembly == "machine_assembly":
|
||||
main.print_bom(True, open(bom_dir + "/bom.txt","wt"))
|
||||
|
||||
for ass in sorted(main.assemblies):
|
||||
f = open(bom_dir + "/" + ass + ".txt", "wt");
|
||||
@@ -134,8 +175,12 @@ def boms(machine):
|
||||
print(" done")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
boms(sys.argv[1])
|
||||
args = len(sys.argv)
|
||||
if args > 1:
|
||||
if args > 2:
|
||||
boms(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
boms(sys.argv[1])
|
||||
else:
|
||||
print("usage: bom [mendel|sturdy|your_machine]")
|
||||
print("usage: bom mendel|sturdy|your_machine [assembly_name]")
|
||||
sys.exit(1)
|
||||
|
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Mendel90
|
||||
//
|
||||
// GNU GPL v2
|
||||
// nop.head@gmail.com
|
||||
// hydraraptor.blogspot.com
|
||||
//
|
||||
// A dummy object to make a BOM
|
||||
//
|
||||
use <main.scad>
|
||||
|
||||
machine_assembly();
|
12
stls.py
12
stls.py
@@ -6,14 +6,18 @@ import shutil
|
||||
import sys
|
||||
import c14n_stl
|
||||
|
||||
source_dir = "scad"
|
||||
from bom import source_dir
|
||||
|
||||
def bom_to_stls(machine):
|
||||
def bom_to_stls(machine, assembly = None):
|
||||
#
|
||||
# Make a list of all the stls in the BOM
|
||||
#
|
||||
stl_files = []
|
||||
for line in open(machine + "/bom/bom.txt", "rt").readlines():
|
||||
if assembly:
|
||||
bom = "accessories/%s.txt" % assembly
|
||||
else:
|
||||
bom = "bom.txt"
|
||||
for line in open(machine + "/bom/" + bom, "rt").readlines():
|
||||
words = line.split()
|
||||
if words:
|
||||
last_word = words[-1]
|
||||
@@ -36,7 +40,7 @@ def stls(machine, parts = None):
|
||||
#
|
||||
# Set the target machine
|
||||
#
|
||||
f = open("scad/conf/machine.scad","wt")
|
||||
f = open(source_dir + "/conf/machine.scad","wt")
|
||||
f. write("include <%s_config.scad>\n" % machine);
|
||||
f.close()
|
||||
|
||||
|
Reference in New Issue
Block a user