def main(): desc = '''Convert an SL1 file to a Photon file.''' parser = argparse.ArgumentParser(description=desc) parser.add_argument("sl1_file", help="SL1 file to convert.") parser.add_argument("-f", "--force", action='store_true', help="overwrite existing files.") # parser.add_argument("--timelapse", action='store_true', default=False, help="set all exposures to 1s. Useful for debugging exposure with no resin.") parser.add_argument("-v", "--verbose", action='store_true', default=False) parser.add_argument("-o", "--output", help="photon file output path.") args = parser.parse_args() # print(args) if args.output is None: base = os.path.splitext(args.sl1_file)[0] photon_path = base + '.photon' else: photon_path = args.output if os.path.exists(photon_path) and args.force is False: print( 'ERROR: file {} already exists!. move or use -f flag to force overwrite. Cancelling...' .format(os.path.basename(photon_path))) sys.exit(-1) sl1 = SL1Reader(args.sl1_file) photon = pyphotonfile.Photon() photon.exposure_time = float(sl1.config['expTime']) photon.exposure_time_bottom = float(sl1.config['expTimeFirst']) photon.layer_height = float(sl1.config['layerHeight']) photon.bottom_layers = int(sl1.config['numFade']) if args.verbose: print('=== PARAMETERS ===') print('Exposure Time: {}'.format(photon.exposure_time)) print('Bottom Exposure Time: {}'.format(photon.exposure_time_bottom)) print('Layer Height: {}'.format(photon.layer_height)) print('Bottom Layers: {}'.format(photon.bottom_layers)) print('Layers: {}'.format(sl1.n_layers)) print('=== CONVERSION ===') with tempfile.TemporaryDirectory() as tmpdirname: if args.verbose: print('extracting layers... ', end='') sl1.extract_images(tmpdirname) if args.verbose: print('DONE') for i, filepath in enumerate( sorted(glob.glob(os.path.join(tmpdirname, '*.png')))): if args.verbose: print('converting layer {} / {} '.format(i + 1, sl1.n_layers), end='') Image.open(filepath).rotate(180).save(filepath) photon.append_layer(filepath) if args.verbose: print('DONE') photon.write(photon_path) print('Output file written to: {}'.format(photon_path))
def convert(self): infile = self.lineEdit_infile.text() outfile = self.lineEdit_outfile.text() if not os.path.exists(infile): ret = QMessageBox.warning(self, "SL1 to Photon Converter", "The selected SL1-File does not exist.", QMessageBox.Ok) return if os.path.exists(outfile): ret = QMessageBox.warning( self, "SL1 to Photon Converter", "The selected Photon-File already exists. Overwrite?", QMessageBox.Yes, QMessageBox.Cancel) if ret == QMessageBox.Cancel: return if outfile.strip() == "": ret = QMessageBox.warning( self, "SL1 to Photon Converter", "Please enter the path to the output file.", QMessageBox.Ok) return sl1 = SL1Reader(infile) photon = pyphotonfile.Photon() photon.exposure_time = self.exposureSpinBox.value() photon.exposure_time_bottom = self.exposureBottomLayersSpinBox.value() photon.layer_height = self.layerHeightDoubleSpinBox.value() photon.bottom_layers = self.bottomLayersSpinBox.value() self.progressBar.setMaximum(sl1.n_layers) self.progressBar.setTextVisible(True) with tempfile.TemporaryDirectory() as tmpdirname: sl1.extract_images(tmpdirname) for i, filepath in enumerate( sorted(glob.glob(os.path.join(tmpdirname, '*.png')))): Image.open(filepath).rotate(180).save(filepath) photon.append_layer(filepath) self.progressBar.setValue(i + 1) QApplication.processEvents() photon.write(outfile) ret = QMessageBox.information(self, "SL1 to Photon Converter", "Done!", QMessageBox.Ok)
parser.add_argument("-o", "--output", help="photon file output path.") args = parser.parse_args() # print(args) if args.output is None: base, ext = os.path.splitext(args.sl1_file) photon_path = base + '.photon' else: photon_path = args.output if os.path.exists(photon_path) and args.force is False: print( 'ERROR: file {} already exists!. move or use -f flag to force overwrite. Cancelling...' .format(os.path.basename(photon_path))) sys.exit(-1) sl1 = SL1Reader(args.sl1_file) photon = pyphotonfile.Photon() photon.exposure_time = float(sl1.config['expTime']) photon.exposure_time_bottom = float(sl1.config['expTimeFirst']) photon.layer_height = float(sl1.config['layerHeight']) photon.bottom_layers = int(sl1.config['numFade']) if args.verbose: print('=== PARAMETERS ===') print('Exposure Time: {}'.format(photon.exposure_time)) print('Bottom Exposure Time: {}'.format(photon.exposure_time_bottom)) print('Layer Height: {}'.format(photon.layer_height)) print('Bottom Layers: {}'.format(photon.bottom_layers)) print('Layers: {}'.format(sl1.n_layers)) print('=== CONVERSION ===') with tempfile.TemporaryDirectory() as tmpdirname: if args.verbose:
def convert(self): infile = self.lineEdit_infile.text() outfile = self.lineEdit_outfile.text() if not os.path.exists(infile): ret = QMessageBox.warning(self, "SL1 to Photon Converter", "The selected SL1-File does not exist.", QMessageBox.Ok) return if os.path.exists(outfile): ret = QMessageBox.warning( self, "SL1 to Photon Converter", "The selected Photon-File already exists. Overwrite?", QMessageBox.Yes, QMessageBox.Cancel) if ret == QMessageBox.Cancel: return if outfile.strip() == "": ret = QMessageBox.warning( self, "SL1 to Photon Converter", "Please enter the path to the output file.", QMessageBox.Ok) return sl1 = SL1Reader(infile) photon = pyphotonfile.Photon() photon.exposure_time = self.exposureDoubleSpinBox.value() photon.exposure_time_bottom = self.exposureBottomLayersSpinBox.value() photon.layer_height = self.layerHeightDoubleSpinBox.value() photon.bottom_layers = self.bottomLayersSpinBox.value() photon.bottom_layer_count = self.bottomLayersSpinBox.value() photon.lifting_speed = self.liftSpeeedSpinBox.value() photon.bottom_lift_speed = self.liftSpeeedSpinBox.value() photon.version = 2 photon.print_properties_length = 60 photon.retract_speed = self.retractSpeeedSpinBox.value() photon.print_time = int(float(sl1.config['printTime'])) photon.anti_aliasing_level = 0 photon.layer_levels = 1 photon.light_pwm = 255 photon.light_pwm_bottom = 255 photon.bottom_lift_distance = 9060 photon.lifting_distance = 5 photon.volume_ml = float(sl1.config['usedMaterial']) photon.weight_g = float(sl1.config['usedMaterial']) photon.cost_dollars = 1 photon.bottom_light_off_delay = 0.0 photon.light_off_delay = 0.0 photon.p1 = 0.0 photon.p2 = 0.0 photon.p3 = 0.0 photon.p4 = 0.0 self.progressBar.setMaximum(sl1.n_layers) self.progressBar.setTextVisible(True) with tempfile.TemporaryDirectory() as tmpdirname: sl1.extract_images(tmpdirname) for i, filepath in enumerate( sorted(glob.glob(os.path.join(tmpdirname, '*.png')))): Image.open(filepath).rotate(180).save(filepath) photon.append_layer(filepath) self.progressBar.setValue(i + 1) QApplication.processEvents() photon.write(outfile) ret = QMessageBox.information(self, "SL1 to Photon Converter", "Done!", QMessageBox.Ok)