diff --git a/docs/usage.md b/docs/usage.md index eeabf1c..ca305db 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -270,6 +270,13 @@ The target config file is selected by generating `target.scad` that includes `co The rest of the project includes `target.scad` to use the configuration. Additionally all the generated file directories (assemblies, bom, stls, dxfs, etc.) are placed in a sub-directory called ``. +The build system will look for a `_assembly` module and use it as the top level module instead of `main_assembly` if it it exists. +That allows the project description to be target specific if the top level modules are in different scad files. +The top level assembly instructions and assembly contents could also be different if appropriate. + +If the top level module is just a shell wrapper that simply includes one other assembly, with no additional parts, then it is removed from the build instructions and +the assembly it calls becomes the top level. This allows a different project description for each target but only one set of top level instructions without repeating them. + ### Other libraries The build scripts need to be able to locate the source files where the modules to generate the STL files and assemblies reside. They will search all the scad files diff --git a/scripts/bom.py b/scripts/bom.py index 69419c4..48267ba 100755 --- a/scripts/bom.py +++ b/scripts/bom.py @@ -46,6 +46,18 @@ def find_scad_file(mname): return filename return None +def main_assembly(target): + file = None + if target: + assembly = target + "_assembly" + file = find_scad_file(assembly) + if not file: + assembly = "main_assembly" + file = find_scad_file(assembly) + if not file: + raise Exception("can't find source for " + assembly) + return assembly, file + class Part: def __init__(self, args): self.count = 1 @@ -221,28 +233,20 @@ def parse_bom(file = "openscad.log", name = None): return main def usage(): - print("\nusage:\n\tbom [target_config] [_assembly] - Generate BOMs for a project or an accessory to a project.") + print("\nusage:\n\tbom [target_config] - Generate BOMs for a project.") sys.exit(1) -def boms(target = None, assembly = None): +def boms(target = None): try: bom_dir = set_config(target, usage) + "bom" - if assembly: - bom_dir += "/accessories" - if not os.path.isdir(bom_dir): - os.makedirs(bom_dir) - else: - assembly = "main_assembly" - if os.path.isdir(bom_dir): - shutil.rmtree(bom_dir) - sleep(0.1) - os.makedirs(bom_dir) + if os.path.isdir(bom_dir): + shutil.rmtree(bom_dir) + sleep(0.1) + os.makedirs(bom_dir) # - # Find the scad file that makes the module + # Find the scad file that makes the main assembly # - scad_file = find_scad_file(assembly) - if not scad_file: - raise Exception("can't find source for " + assembly) + assembly, scad_file = main_assembly(target) # # make a file to use the module # @@ -259,8 +263,7 @@ def boms(target = None, assembly = None): main = parse_bom("openscad.echo", assembly) - if assembly == "main_assembly": - main.print_bom(True, open(bom_dir + "/bom.txt","wt")) + main.print_bom(True, open(bom_dir + "/bom.txt","wt")) for ass in main.assemblies: with open(bom_dir + "/" + ass + ".txt", "wt") as f: @@ -278,20 +281,8 @@ def boms(target = None, assembly = None): sys.exit(1) if __name__ == '__main__': - if len(sys.argv) > 3: usage() + if len(sys.argv) > 2: usage() - if len(sys.argv) == 3: - target, assembly = sys.argv[1], sys.argv[2] - else: - if len(sys.argv) == 2: - if sys.argv[1][-9:] == "_assembly": - target, assembly = None, sys.argv[1] - else: - target, assembly = sys.argv[1], None - else: - target, assembly = None, None + target = sys.argv[1] if len(sys.argv) == 2 else None - if assembly: - if assembly[-9:] != "_assembly": usage() - - boms(target, assembly) + boms(target) diff --git a/scripts/views.py b/scripts/views.py index d827a8c..074e389 100755 --- a/scripts/views.py +++ b/scripts/views.py @@ -161,6 +161,7 @@ def views(target, do_assemblies = None): # Find all the scad files # main_blurb = None + main_assembly, main_file = bom.main_assembly(target) pngs = [] for dir in source_dirs(bom_dir): if os.path.isdir(dir): @@ -232,7 +233,7 @@ def views(target, do_assemblies = None): update_image(tmp_name, tn_name) done_assemblies.append(real_name) else: - if module == 'main_assembly': + if module == main_assembly: main_blurb = blurb.scrape_module_blurb(lines[:line_no]) line_no += 1 # @@ -246,9 +247,6 @@ def views(target, do_assemblies = None): project = ' '.join(word[0].upper() + word[1:] for word in os.path.basename(os.getcwd()).split('_')) print('', file = doc_file) print('# %s' % project, file = doc_file) - main_file = bom.find_scad_file('main_assembly') - if not main_file: - raise Exception("can't find source for main_assembly") text = blurb.scrape_blurb(source_dir + '/' + main_file) blurbs = blurb.split_blurb(text) if len(text):