public void RunRawCode(InputImage[] images, string rawCode) { string pythonCode = this.GetFunctionCode(rawCode); dynamic scope = engine.CreateScope(); try { engine.Execute(pythonCode, scope); } catch (SyntaxErrorException ex) { engine = null; scope = null; ExceptionOperations eo = engine.GetService<ExceptionOperations>(); MessageBox.Show(eo.FormatException(ex)); } if (engine == null || scope == null) { throw new Exception("Cannot create Python engine!"); } ImageExtensions.SaveAction = saveCallback; foreach (var inputImage in images) { Image imageCopy = new Image(inputImage.SourceImage); try { scope.ProcessImage(imageCopy); } catch (Exception ex) { throw new Exception("Error processing " + inputImage.SourceImage.Filename + ": " + ex.Message); } } }