diff --git a/scripts/exports.py b/scripts/exports.py index 55ddbf4..dd8117c 100644 --- a/scripts/exports.py +++ b/scripts/exports.py @@ -86,47 +86,48 @@ def make_parts(target, part_type, parts = None): lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed' module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type for dir in [source_dir, source_dir + '/printed', lib_dir]: - for filename in os.listdir(dir): - if filename[-5:] == ".scad": - # - # find any modules ending in _ - # - with open(dir + "/" + filename, "r") as f: - for line in f.readlines(): - words = line.split() - if(len(words) and words[0] == "module"): - module = words[1].split('(')[0] - if module.endswith(module_suffix): - base_name = module[:-4] - part = base_name + '.' + part_type - if part in targets: - # - # make a file to use the module - # - part_maker_name = part_type + ".scad" - with open(part_maker_name, "w") as f: - f.write("use <%s/%s>\n" % (dir, filename)) - f.write("%s();\n" % module); - # - # Run openscad on the created file - # - part_file = target_dir + "/" + part - dname = deps_name(deps_dir, filename) - changed = check_deps(part_file, dname) - changed = times.check_have_time(changed, part) - if part_type == 'stl' and not changed and not part in bounds_map: - changed = "No bounds" - if changed: - print(changed) - t = time.time() - openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name) - times.add_time(part, t) - if part_type == 'stl': - bounds = c14n_stl.canonicalise(part_file) - bounds_map[part] = bounds + if os.path.isdir(dir): + for filename in os.listdir(dir): + if filename[-5:] == ".scad": + # + # find any modules ending in _ + # + with open(dir + "/" + filename, "r") as f: + for line in f.readlines(): + words = line.split() + if(len(words) and words[0] == "module"): + module = words[1].split('(')[0] + if module.endswith(module_suffix): + base_name = module[:-4] + part = base_name + '.' + part_type + if part in targets: + # + # make a file to use the module + # + part_maker_name = part_type + ".scad" + with open(part_maker_name, "w") as f: + f.write("use <%s/%s>\n" % (dir, filename)) + f.write("%s();\n" % module); + # + # Run openscad on the created file + # + part_file = target_dir + "/" + part + dname = deps_name(deps_dir, filename) + changed = check_deps(part_file, dname) + changed = times.check_have_time(changed, part) + if part_type == 'stl' and not changed and not part in bounds_map: + changed = "No bounds" + if changed: + print(changed) + t = time.time() + openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name) + times.add_time(part, t) + if part_type == 'stl': + bounds = c14n_stl.canonicalise(part_file) + bounds_map[part] = bounds - targets.remove(part) - os.remove(part_maker_name) + targets.remove(part) + os.remove(part_maker_name) # # Write new bounds file # diff --git a/scripts/views.py b/scripts/views.py index a040b39..1db9fc4 100755 --- a/scripts/views.py +++ b/scripts/views.py @@ -125,65 +125,66 @@ def views(target, do_assemblies = None): main_blurb = None lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed' for dir in [source_dir, source_dir + '/printed', lib_dir]: - for filename in os.listdir(dir): - if filename.endswith('.scad'): - # - # find any modules with names ending in _assembly - # - with open(dir + "/" + filename, "r") as f: - lines = f.readlines() - line_no = 0 - for line in lines: - words = line.split() - if len(words) and words[0] == "module": - module = words[1].split('(')[0] - if is_assembly(module): - if module in assemblies: - # - # Scrape the assembly instructions - # - for ass in flat_bom: - if ass["name"] == module: - if not "blurb" in ass: - ass["blurb"] = blurb.scrape_module_blurb(lines[:line_no]) - break - if not do_assemblies or module in do_assemblies: + if os.path.isdir(dir): + for filename in os.listdir(dir): + if filename.endswith('.scad'): + # + # find any modules with names ending in _assembly + # + with open(dir + "/" + filename, "r") as f: + lines = f.readlines() + line_no = 0 + for line in lines: + words = line.split() + if len(words) and words[0] == "module": + module = words[1].split('(')[0] + if is_assembly(module): + if module in assemblies: # - # make a file to use the module + # Scrape the assembly instructions # - png_maker_name = 'png.scad' - with open(png_maker_name, "w") as f: - f.write("use <%s/%s>\n" % (dir, filename)) - f.write("%s();\n" % module); - # - # Run openscad on the created file - # - dname = deps_name(deps_dir, filename) - for explode in [0, 1]: - png_name = target_dir + '/' + module + '.png' - if not explode: - png_name = png_name.replace('_assembly', '_assembled') - changed = check_deps(png_name, dname) - changed = times.check_have_time(changed, png_name) - changed = options.have_changed(changed, png_name) - tmp_name = 'tmp.png' - if changed: - print(changed) - t = time.time() - openscad.run_list(options.list() + ["-D$pose=1", "-D$explode=%d" % explode, colour_scheme, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, png_maker_name]); - times.add_time(png_name, t) - do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", background, "-border", "10", tmp_name]) - update_image(tmp_name, png_name) - tn_name = png_name.replace('.png', '_tn.png') - if mtime(png_name) > mtime(tn_name): - do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background " + background + " -gravity Center -extent 280x280 -bordercolor " + background + " -border 10 " + tmp_name).split()) - update_image(tmp_name, tn_name) - os.remove(png_maker_name) - done_assemblies.append(module) - else: - if module == 'main_assembly': - main_blurb = blurb.scrape_module_blurb(lines[:line_no]) - line_no += 1 + for ass in flat_bom: + if ass["name"] == module: + if not "blurb" in ass: + ass["blurb"] = blurb.scrape_module_blurb(lines[:line_no]) + break + if not do_assemblies or module in do_assemblies: + # + # make a file to use the module + # + png_maker_name = 'png.scad' + with open(png_maker_name, "w") as f: + f.write("use <%s/%s>\n" % (dir, filename)) + f.write("%s();\n" % module); + # + # Run openscad on the created file + # + dname = deps_name(deps_dir, filename) + for explode in [0, 1]: + png_name = target_dir + '/' + module + '.png' + if not explode: + png_name = png_name.replace('_assembly', '_assembled') + changed = check_deps(png_name, dname) + changed = times.check_have_time(changed, png_name) + changed = options.have_changed(changed, png_name) + tmp_name = 'tmp.png' + if changed: + print(changed) + t = time.time() + openscad.run_list(options.list() + ["-D$pose=1", "-D$explode=%d" % explode, colour_scheme, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, png_maker_name]); + times.add_time(png_name, t) + do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", background, "-border", "10", tmp_name]) + update_image(tmp_name, png_name) + tn_name = png_name.replace('.png', '_tn.png') + if mtime(png_name) > mtime(tn_name): + do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background " + background + " -gravity Center -extent 280x280 -bordercolor " + background + " -border 10 " + tmp_name).split()) + update_image(tmp_name, tn_name) + os.remove(png_maker_name) + done_assemblies.append(module) + else: + if module == 'main_assembly': + main_blurb = blurb.scrape_module_blurb(lines[:line_no]) + line_no += 1 times.print_times() # # Build the document