public ContinueLooking(CannotFindFileVM vm)
 {
     this.vm          = vm;
     this.DataContext = vm;
     InitializeComponent();
 }
        void batchPrint()
        {
            Transaction trans = new Transaction(commandData.Application.ActiveUIDocument.Document, "WW_PDF");

            trans.Start();

            string printSetting = "A1 TO A1";

            var doc = commandData.Application.ActiveUIDocument.Document;

            var printM = commandData.Application.ActiveUIDocument.Document.PrintManager;

            printM.SelectNewPrintDriver("Bluebeam PDF");

            var            ps = new FilteredElementCollector(doc);
            List <Element> myPrintSettings = ps.OfClass(typeof(PrintSetting)).ToList();

            foreach (var setting in myPrintSettings)
            {
                if (setting.Name == printSetting)
                {
                    printM.PrintSetup.CurrentPrintSetting = setting as PrintSetting;
                }
            }

            printM.PrintToFile = true;

            string dest = "";

            if (CopyToFolder)
            {
                FolderBrowserDialog folderDlg = new FolderBrowserDialog();
                folderDlg.ShowNewFolderButton = true;
                DialogResult result = folderDlg.ShowDialog();
                if (result == DialogResult.OK)
                {
                    dest = folderDlg.SelectedPath;
                }
            }

            string        output           = "Sheets printed: " + Environment.NewLine;
            List <string> printedFileNames = new List <string>();

            foreach (var sheet in SheetInfo)
            {
                if (sheet.ToPrint)
                {
                    output += sheet.Number + " " + sheet.Name + Environment.NewLine;
                    var fp = sheet.FilePath;
                    printM.PrintToFileName = fp;
                    printedFileNames.Add(fp);
                    printM.SubmitPrint(sheet.Sheet);

                    string dwgFilepath = Path.GetDirectoryName(fp);
                    string dwgfileName = Path.GetFileNameWithoutExtension(fp) + @".dwg";
                    var    dwgxopt     = new DWGExportOptions();
                    dwgxopt.MergedViews = true;
                    doc.Export(dwgFilepath, dwgfileName, new List <ElementId> {
                        sheet.ElementID
                    }, dwgxopt);
                }
            }

            if (CopyToFolder)
            {
                foreach (var fileName in printedFileNames)
                {
                    int waitCycles      = 0;
                    CannotFindFileVM vm = new CannotFindFileVM();
                    while (!File.Exists(fileName))
                    {
                        Thread.Sleep(1000);
                        waitCycles++;
                        if (waitCycles > 15)
                        {
                            var skipFile    = new Window();
                            var userControl = new ContinueLooking(vm);
                            var window      = new Window()
                            {
                                Content = userControl
                            };
                            window.ShowDialog();
                        }
                        if (vm.SkipAll == true || vm.SkipOne == true)
                        {
                            break;
                        }
                    }
                    if (vm.SkipOne == false && vm.SkipAll == false)
                    {
                        string file = Path.GetFileName(fileName);
                        File.Copy(fileName, dest + @"\" + file, true);
                    }
                    else
                    {
                        if (vm.SkipAll == true)
                        {
                            break;
                        }
                    }
                }
            }
            trans.Commit();
        }