def compile_vitamin(v, dom): temp_name = "temp.scad" # # Make the target directories # target_dir = "../vitamins/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../vitamins/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # Compile print(" " + v['title']) fn = '../' + v['file'] if (os.path.isfile(fn)): print(" Checking csg hash") h = openscad.get_csg_hash(temp_name, v['call'], [fn]) os.remove(temp_name) hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v) # update hash in json v['hash'] = h # STL print(" STL Parts") for part in v['children']: if type(part) is DictType and part['type'] == 'part': stlpath = target_dir + '/' + openscad.stl_filename( part['title']) if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") openscad.render_stl(temp_name, stlpath, part['call'], [fn]) else: print(" STL up to date") # Views print(" Views") for view in v['children']: if type(view) is DictType and view['type'] == 'view': print(" " + view['title']) render_view(v['title'], v['call'], view_dir, view, hashchanged, h, [fn], False) png_name = view_dir + '/' + view_filename(v['title'] + '_' + view['title']) view['png_name'] = png_name node = add_vitamin(v, dom) else: print(" Error: scad file not found: " + v['file'])
def compile_vitamin(v, dom): temp_name = "temp.scad" # # Make the target directories # target_dir = "../vitamins/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../vitamins/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # Compile print(" "+v['title']) fn = '../' + v['file'] if (os.path.isfile(fn)): print(" Checking csg hash") h = openscad.get_csg_hash(temp_name, v['call'], [fn]); os.remove(temp_name); hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v) # update hash in json v['hash'] = h # STL print(" STL Parts") for part in v['children']: if type(part) is DictType and part['type'] == 'part': stlpath = target_dir + '/' + openscad.stl_filename(part['title']) if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") openscad.render_stl(temp_name, stlpath, part['call'], [fn]) else: print(" STL up to date") # Views print(" Views") for view in v['children']: if type(view) is DictType and view['type'] == 'view': print(" "+view['title']) render_view(v['title'], v['call'], view_dir, view, hashchanged, h, [fn], False) png_name = view_dir + '/' + view_filename(v['title'] + '_' + view['title']) view['png_name'] = png_name node = add_vitamin(v, dom) else: print(" Error: scad file not found: "+v['file'])
def compile_vitamin(v): # # Make the target directories # if not os.path.isdir(config.paths['vitaminsstl']): os.makedirs(config.paths['vitaminsstl']) if not os.path.isdir(config.paths['vitaminsimages2']): os.makedirs(config.paths['vitaminsimages2']) # Compile print(" " + v['title']) fn = os.path.join('..', v['file']) if (os.path.isfile(fn)): print(" Checking csg hash") h = openscad.get_csg_hash(config.paths['tempscad'], v['call']) os.remove(config.paths['tempscad']) hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v) # update hash in json v['hash'] = h # STL print(" STL Parts") if 'parts' in v: for part in v['parts']: stlpath = os.path.join(config.paths['vitaminsstl'], openscad.stl_filename(part['title'])) if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") openscad.render_stl(config.paths['tempscad'], stlpath, part['call']) else: print(" STL up to date") # Views print(" Views") for view in v['views']: print(" " + view['title']) render_view(v['title'], v['call'], config.paths['vitaminsimages2'], view, hashchanged, h) else: print(" Error: scad file not found: " + v['file'])
def printed(): print("Printed Parts") print("-------------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../printedparts/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) # store a list of valid STLs to aid cleanup stlList = [] view_dir = "../printedparts/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json", "r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) pl = m['printed'] for p in pl: print(" " + p['title']) fn = '../' + p['file'] if (os.path.isfile(fn)): stlpath = os.path.join(target_dir, openscad.stl_filename(p['title'])) md5path = os.path.join( target_dir, openscad.stl_filename(p['title']) + '.md5') print(" Checking csg hash") # Get csg hash h = openscad.get_csg_hash(temp_name, p['call']) os.remove(temp_name) # Get old csg hash oldh = "" if os.path.isfile(md5path): with open(md5path, 'r') as f: oldh = f.read() hashchanged = h != oldh # update hash in json p['hash'] = h # save new hash with open(md5path, 'w') as f: f.write(h) # STL print(" STL") if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") info = openscad.render_stl(temp_name, stlpath, p['call']) jsontools.json_merge_missing_keys(p, info) # Slice for weight and volume print(" Slice") if hashchanged or ('plasticWeight' not in p): # Slice part and track volume of plastic required # Estimate KG of plastic from density range: 1.23-1.25 g/cm3 plasticInfo = slic3r.calc_plastic_required(stlpath) jsontools.json_merge_missing_keys(p, plasticInfo) else: print(" GCode up to date") print(" views") # Views for view in p['views']: print(" " + view['title']) render_view(p['title'], p['call'], view_dir, view, hashchanged, h) # Add to stlList stlList.append(stlpath) stlList.append(md5path) else: print(" Error: scad file not found: " + p['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write( json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) # clean-up orphaned stls and checksums print "Checking for outdated STLs..." for f in os.listdir(target_dir): fp = os.path.join(target_dir, f) try: if os.path.isfile(fp) and (fp not in stlList): print "Removing: " + fp os.remove(fp) except Exception, e: print e
def vitamins(): print("Vitamins") print("--------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../vitamins/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../vitamins/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json", "r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) vl = m['vitamins'] for v in vl: print(" " + v['title']) fn = '../' + v['file'] if (os.path.isfile(fn)): print(" Checking csg hash") h = openscad.get_csg_hash(temp_name, v['call']) os.remove(temp_name) hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v) # update hash in json v['hash'] = h # STL print(" STL Parts") if 'parts' in v: for part in v['parts']: stlpath = target_dir + '/' + openscad.stl_filename( part['title']) if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") openscad.render_stl(temp_name, stlpath, part['call']) else: print(" STL up to date") # Views print(" Views") for view in v['views']: print(" " + view['title']) render_view(v['title'], v['call'], view_dir, view, hashchanged, h) else: print(" Error: scad file not found: " + v['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write( json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) return 0
def printed(): print("Printed Parts") print("-------------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../printedparts/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../printedparts/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json","r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) pl = m['printed'] for p in pl: print(" "+p['title']) fn = '../' + p['file'] if (os.path.isfile(fn)): stlpath = target_dir + '/' + openscad.stl_filename(p['title']) md5path = target_dir + '/' + openscad.stl_filename(p['title']) + '.md5' print(" Checking csg hash") # Get csg hash h = openscad.get_csg_hash(temp_name, p['call']); os.remove(temp_name); # Get old csg hash oldh = "" if os.path.isfile(md5path): with open(md5path,'r') as f: oldh = f.read() hashchanged = h != oldh # update hash in json p['hash'] = h # save new hash with open(md5path,'w') as f: f.write(h) # STL print(" STL") if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") info = openscad.render_stl(temp_name, stlpath, p['call']) jsontools.json_merge_missing_keys(p, info) else: print(" STL up to date") print(" views") # Views for view in p['views']: print(" "+view['title']) render_view(p['title'], p['call'], view_dir, view, hashchanged, h) else: print(" Error: scad file not found: "+p['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) return 0
def printed(): print("Printed Parts") print("-------------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../printedparts/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../printedparts/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json", "r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) pl = m['printed'] for p in pl: print(" " + p['title']) fn = '../' + p['file'] if (os.path.isfile(fn)): stlpath = target_dir + '/' + openscad.stl_filename( p['title']) md5path = target_dir + '/' + openscad.stl_filename( p['title']) + '.md5' print(" Checking csg hash") # Get csg hash h = openscad.get_csg_hash(temp_name, p['call']) os.remove(temp_name) # Get old csg hash oldh = "" if os.path.isfile(md5path): with open(md5path, 'r') as f: oldh = f.read() hashchanged = h != oldh # update hash in json p['hash'] = h # save new hash with open(md5path, 'w') as f: f.write(h) # STL print(" STL") if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") info = openscad.render_stl(temp_name, stlpath, p['call']) jsontools.json_merge_missing_keys(p, info) else: print(" STL up to date") print(" views") # Views for view in p['views']: print(" " + view['title']) render_view(p['title'], p['call'], view_dir, view, hashchanged, h) else: print(" Error: scad file not found: " + p['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write( json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) return 0
def vitamins(): print("Vitamins") print("--------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../vitamins/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) view_dir = "../vitamins/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json","r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) vl = m['vitamins'] for v in vl: print(" "+v['title']) fn = '../' + v['file'] if (os.path.isfile(fn)): print(" Checking csg hash") h = openscad.get_csg_hash(temp_name, v['call']); os.remove(temp_name); hashchanged = ('hash' in v and h != v['hash']) or (not 'hash' in v) # update hash in json v['hash'] = h # STL print(" STL Parts") if 'parts' in v: for part in v['parts']: stlpath = target_dir + '/' + openscad.stl_filename(part['title']) if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") openscad.render_stl(temp_name, stlpath, part['call']) else: print(" STL up to date") # Views print(" Views") for view in v['views']: print(" "+view['title']) render_view(v['title'], v['call'], view_dir, view, hashchanged, h) else: print(" Error: scad file not found: "+v['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) return 0
def printed(): print("Printed Parts") print("-------------") temp_name = "temp.scad" # # Make the target directories # target_dir = "../printedparts/stl" if not os.path.isdir(target_dir): os.makedirs(target_dir) # store a list of valid STLs to aid cleanup stlList = [] view_dir = "../printedparts/images" if not os.path.isdir(view_dir): os.makedirs(view_dir) # load hardware.json jf = open("hardware.json","r") jso = json.load(jf) jf.close() # for each machine for m in jso: if type(m) is DictType and m['type'] == 'machine': print(m['title']) pl = m['printed'] for p in pl: print(" "+p['title']) fn = '../' + p['file'] if (os.path.isfile(fn)): stlpath = os.path.join(target_dir, openscad.stl_filename(p['title'])) md5path = os.path.join(target_dir, openscad.stl_filename(p['title']) + '.md5') print(" Checking csg hash") # Get csg hash h = openscad.get_csg_hash(temp_name, p['call']); os.remove(temp_name); # Get old csg hash oldh = "" if os.path.isfile(md5path): with open(md5path,'r') as f: oldh = f.read() hashchanged = h != oldh # update hash in json p['hash'] = h # save new hash with open(md5path,'w') as f: f.write(h) # STL print(" STL") if hashchanged or (not os.path.isfile(stlpath)): print(" Rendering STL...") info = openscad.render_stl(temp_name, stlpath, p['call']) jsontools.json_merge_missing_keys(p, info) # Slice for weight and volume print(" Slice") if hashchanged or ('plasticWeight' not in p): # Slice part and track volume of plastic required # Estimate KG of plastic from density range: 1.23-1.25 g/cm3 plasticInfo = slic3r.calc_plastic_required(stlpath) jsontools.json_merge_missing_keys(p, plasticInfo) else: print(" GCode up to date") print(" views") # Views for view in p['views']: print(" "+view['title']) render_view(p['title'], p['call'], view_dir, view, hashchanged, h) # Add to stlList stlList.append(stlpath) stlList.append(md5path) else: print(" Error: scad file not found: "+p['file']) # Save changes to json with open('hardware.json', 'w') as f: f.write(json.dumps(jso, sort_keys=False, indent=4, separators=(',', ': '))) # clean-up orphaned stls and checksums print "Checking for outdated STLs..." for f in os.listdir(target_dir): fp = os.path.join(target_dir, f) try: if os.path.isfile(fp) and (fp not in stlList): print "Removing: "+fp os.remove(fp) except Exception, e: print e