1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-05 15:07:28 +02:00

Fix for printed directory not present.

This commit is contained in:
Chris Palmer
2020-02-24 23:58:22 +00:00
parent dcb1e74894
commit e9bc300b8d
2 changed files with 99 additions and 97 deletions

View File

@@ -86,47 +86,48 @@ def make_parts(target, part_type, parts = None):
lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed' lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed'
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
for dir in [source_dir, source_dir + '/printed', lib_dir]: for dir in [source_dir, source_dir + '/printed', lib_dir]:
for filename in os.listdir(dir): if os.path.isdir(dir):
if filename[-5:] == ".scad": for filename in os.listdir(dir):
# if filename[-5:] == ".scad":
# find any modules ending in _<part_type> #
# # find any modules ending in _<part_type>
with open(dir + "/" + filename, "r") as f: #
for line in f.readlines(): with open(dir + "/" + filename, "r") as f:
words = line.split() for line in f.readlines():
if(len(words) and words[0] == "module"): words = line.split()
module = words[1].split('(')[0] if(len(words) and words[0] == "module"):
if module.endswith(module_suffix): module = words[1].split('(')[0]
base_name = module[:-4] if module.endswith(module_suffix):
part = base_name + '.' + part_type base_name = module[:-4]
if part in targets: part = base_name + '.' + part_type
# if part in targets:
# make a file to use the module #
# # make a file to use the module
part_maker_name = part_type + ".scad" #
with open(part_maker_name, "w") as f: part_maker_name = part_type + ".scad"
f.write("use <%s/%s>\n" % (dir, filename)) with open(part_maker_name, "w") as f:
f.write("%s();\n" % module); f.write("use <%s/%s>\n" % (dir, filename))
# f.write("%s();\n" % module);
# Run openscad on the created file #
# # Run openscad on the created file
part_file = target_dir + "/" + part #
dname = deps_name(deps_dir, filename) part_file = target_dir + "/" + part
changed = check_deps(part_file, dname) dname = deps_name(deps_dir, filename)
changed = times.check_have_time(changed, part) changed = check_deps(part_file, dname)
if part_type == 'stl' and not changed and not part in bounds_map: changed = times.check_have_time(changed, part)
changed = "No bounds" if part_type == 'stl' and not changed and not part in bounds_map:
if changed: changed = "No bounds"
print(changed) if changed:
t = time.time() print(changed)
openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name) t = time.time()
times.add_time(part, t) openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name)
if part_type == 'stl': times.add_time(part, t)
bounds = c14n_stl.canonicalise(part_file) if part_type == 'stl':
bounds_map[part] = bounds bounds = c14n_stl.canonicalise(part_file)
bounds_map[part] = bounds
targets.remove(part) targets.remove(part)
os.remove(part_maker_name) os.remove(part_maker_name)
# #
# Write new bounds file # Write new bounds file
# #

View File

@@ -125,65 +125,66 @@ def views(target, do_assemblies = None):
main_blurb = None main_blurb = None
lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed' lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed'
for dir in [source_dir, source_dir + '/printed', lib_dir]: for dir in [source_dir, source_dir + '/printed', lib_dir]:
for filename in os.listdir(dir): if os.path.isdir(dir):
if filename.endswith('.scad'): for filename in os.listdir(dir):
# if filename.endswith('.scad'):
# find any modules with names ending in _assembly #
# # find any modules with names ending in _assembly
with open(dir + "/" + filename, "r") as f: #
lines = f.readlines() with open(dir + "/" + filename, "r") as f:
line_no = 0 lines = f.readlines()
for line in lines: line_no = 0
words = line.split() for line in lines:
if len(words) and words[0] == "module": words = line.split()
module = words[1].split('(')[0] if len(words) and words[0] == "module":
if is_assembly(module): module = words[1].split('(')[0]
if module in assemblies: 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:
# #
# make a file to use the module # Scrape the assembly instructions
# #
png_maker_name = 'png.scad' for ass in flat_bom:
with open(png_maker_name, "w") as f: if ass["name"] == module:
f.write("use <%s/%s>\n" % (dir, filename)) if not "blurb" in ass:
f.write("%s();\n" % module); ass["blurb"] = blurb.scrape_module_blurb(lines[:line_no])
# break
# Run openscad on the created file if not do_assemblies or module in do_assemblies:
# #
dname = deps_name(deps_dir, filename) # make a file to use the module
for explode in [0, 1]: #
png_name = target_dir + '/' + module + '.png' png_maker_name = 'png.scad'
if not explode: with open(png_maker_name, "w") as f:
png_name = png_name.replace('_assembly', '_assembled') f.write("use <%s/%s>\n" % (dir, filename))
changed = check_deps(png_name, dname) f.write("%s();\n" % module);
changed = times.check_have_time(changed, png_name) #
changed = options.have_changed(changed, png_name) # Run openscad on the created file
tmp_name = 'tmp.png' #
if changed: dname = deps_name(deps_dir, filename)
print(changed) for explode in [0, 1]:
t = time.time() png_name = target_dir + '/' + module + '.png'
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]); if not explode:
times.add_time(png_name, t) png_name = png_name.replace('_assembly', '_assembled')
do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", background, "-border", "10", tmp_name]) changed = check_deps(png_name, dname)
update_image(tmp_name, png_name) changed = times.check_have_time(changed, png_name)
tn_name = png_name.replace('.png', '_tn.png') changed = options.have_changed(changed, png_name)
if mtime(png_name) > mtime(tn_name): tmp_name = 'tmp.png'
do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background " + background + " -gravity Center -extent 280x280 -bordercolor " + background + " -border 10 " + tmp_name).split()) if changed:
update_image(tmp_name, tn_name) print(changed)
os.remove(png_maker_name) t = time.time()
done_assemblies.append(module) 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]);
else: times.add_time(png_name, t)
if module == 'main_assembly': do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", background, "-border", "10", tmp_name])
main_blurb = blurb.scrape_module_blurb(lines[:line_no]) update_image(tmp_name, png_name)
line_no += 1 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() times.print_times()
# #
# Build the document # Build the document