private void Publisher_ValueDataPublisher(object sender, SSDLPlotingPublisher.MessageArgument <double> e) { //pbStatus.Dispatcher.Invoke(() => { pbStatus.Value = pbStatus.Value + e.Message; }); //txtPercentage.Dispatcher.Invoke(() => //{ // var value = Convert.ToInt32((pbStatus.Value / pbStatus.Maximum) * 100); // txtPercentage.Text = value + "%"; //}); DoEventsHandler.DoEvents(); }
private void generatePDF(string BOMExcel) { string docName = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name; try { Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; acDoc.Database.SaveAs(acDoc.Name, true, DwgVersion.Current, acDoc.Database.SecurityParameters); } catch (Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString()); } if (AcadFunctions.AcadLayersList.Count > 0) { if (Layerlisodwg.Any(x => x.Include)) { InitializeLayouts(); Document docPublish = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; var lstLayers = Layerlisodwg.Where(x => x.Include && x.EntityAvail).Select(x => x).ToList(); ProgressHeaderPublisher.PublishData("Processing..."); ProgressStatusPublisher.PublishData(""); ProgressBarMaximumPublisher.PublishData(lstLayers.Count + 1); int cnt = 0; bool Page_1Available = false; if (lstLayers.ToList().Count > 0) { Page_1Available = lstLayers.Where(a => a.Include == true && (a.LayerName.Equals("PAGE_1", StringComparison.InvariantCultureIgnoreCase) || a.LayerName.Equals("PAGE1", StringComparison.InvariantCultureIgnoreCase))).Any(); } lstLayers.ToList().ForEach(x => { cnt++; ProgressHeaderPublisher.PublishData("Processing " + cnt + " of " + lstLayers.Count); ProgressStatusPublisher.PublishData("Publishing " + x.LayerName + "..."); if (x.Include) { var layerName = x.LayerName; OnOrOffParticularLayer(true, layerName, Page_1Available); docPublish.SendStringToExecute("zoom e ", true, false, true); Thread.Sleep(1000); new SingleSheetPdf(_pdfLocation, GetLayoutIdList(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database)).PublishNew(_pdfLocation, x.LayerName); OnOrOffParticularLayer(false, layerName, Page_1Available); } ProgressValuePublisher.PublishData(1); }); SetDefaultLayout(docPublish); OffAllLayers(true); ProgressHeaderPublisher.PublishData("Processing...."); ProgressStatusPublisher.PublishData("Merging pdf"); try { string path = _pdfLocation; string[] pdfFiles = Directory.GetFiles(path, "*.pdf").Select(f => new FileInfo(f)).OrderBy(f => f.CreationTime).Select(d => d.FullName).ToArray(); var completedFiles = new List <string>(); docName = System.IO.Path.GetFileNameWithoutExtension(docName); foreach (var item in pdfFiles) { if (System.IO.Path.GetFileNameWithoutExtension(item).StartsWith(docName)) { var layer = Layerlisodwg.Where(y => y.Include && item.Contains(y.LayerName)).Select(y => y).FirstOrDefault(); if (layer != null) { completedFiles.Add(item); } } } statusText = "Appending BOM Spreadsheet to PDF... (Task 6 of 6)"; lblpbBarContent.Content = statusText; pbBar.Value = pbBar.Value + 10; DoEventsHandler.DoEvents(); // step 1: creation of a document-object iTextSharp.text.Document document = new iTextSharp.text.Document(); if (File.Exists(System.IO.Path.Combine(path, docName + ".pdf"))) { File.Delete(System.IO.Path.Combine(path, docName + ".pdf")); } if (completedFiles.Count > 0) { // step 2: we create a writer that listens to the document PdfCopy writer = new PdfCopy(document, new FileStream(System.IO.Path.Combine(path, docName + ".pdf"), FileMode.Create)); if (writer == null) { return; } // step 3: we open the document document.Open(); foreach (string fileName in completedFiles) { // we create a reader for a certain document PdfReader reader = new PdfReader(fileName); reader.ConsolidateNamedDestinations(); // step 4: we add content for (int i = 1; i <= reader.NumberOfPages; i++) { PdfImportedPage page = writer.GetImportedPage(reader, i); writer.AddPage(page); } PRAcroForm form = reader.AcroForm; if (form != null) { writer.CopyAcroForm(reader); } reader.Close(); } // step 5: we close the document and writer writer.Close(); document.Close(); if (System.IO.File.Exists(BOMExcel)) { String strDwgPDF = System.IO.Path.Combine(path, docName + ".pdf"); string strBOMPDF = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(BOMExcel), System.IO.Path.GetFileNameWithoutExtension(BOMExcel) + ".pdf"); string strResultPDF = System.IO.Path.Combine(path, docName + "_PROD.pdf"); string shellCommand = "C:\\ACAD2018_LivaNova\\Interface\\PDFTK.exe " + strDwgPDF + " " + strBOMPDF + " cat output " + strResultPDF; AcadCommands oAcad = new AcadCommands(); oAcad.ExecuteCommandSync(shellCommand); } foreach (var item in completedFiles) { try { if (System.IO.File.Exists(item)) { System.IO.File.Delete(item); } } catch { } } ProgressValuePublisher.PublishData(1); ProgressHeaderPublisher.PublishData("Processed " + cnt + " of " + lstLayers.Count); ProgressStatusPublisher.PublishData("Completed"); //MessageBox.Show("PDF Generation Completed", Title, MessageBoxButton.OK, MessageBoxImage.Information); //10-05-2018 if (System.IO.File.Exists(System.IO.Path.Combine(path, docName + "_PROD.pdf"))) { System.Diagnostics.Process.Start(System.IO.Path.Combine(path, docName + "_PROD.pdf")); //System.IO.File.Open(System.IO.Path.Combine(path, docName + ".pdf"), FileMode.Open); } } else { ProgressValuePublisher.PublishData(1); ProgressHeaderPublisher.PublishData("Processed " + cnt + " of " + lstLayers.Count); ProgressStatusPublisher.PublishData("Failed"); MessageBox.Show("Failed to merge pdf.", Title, MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { } } else { MessageBox.Show("Atleast one layer should be selected.", Title, MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private void implementFn() { IniFile getpath = new IniFile(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Settings.ini")); string path = getpath.IniReadValue("FilePath", "BOM_OUTPUT_LOCATION"); string BOMExcelfulltitle = System.IO.Path.Combine(path, System.IO.Path.GetFileNameWithoutExtension(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name) + "_BOM.xlsx"); //string BOMExcelfulltitle = System.IO.Path.Combine(path, System.IO.Path.GetFileNameWithoutExtension(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name) + "_"+DateTime.Now.ToString("yyyy_MM_dd")+"_XML.xlsx"); //Generate button functionality //Create BOM Excel try { statusText = "Generating Production Drawing…"; lblpbBarContent.Content = statusText; pbBar.Value = (5); DoEventsHandler.DoEvents(); statusText = "Re-populating Drawing Item Numbers... (Task 1 of 6)"; lblpbBarContent.Content = statusText; pbBar.Value = (8); DoEventsHandler.DoEvents(); statusText = "Generating BOM Spreadsheet... (Task 2 of 6)"; lblpbBarContent.Content = statusText; pbBar.Value = 10; DoEventsHandler.DoEvents(); BOM od = new BOM(); od.strBomName = textBoxdesc.Text; od.Generate(ExcelOutput: true); //statusText = "Generating BOM Spreadsheet... (Task 2 of 6)"; //lblpbBarContent.Content = statusText; ////pbBar.Value = (40); //pbBar.Value = pbBar.Value + 10; //DoEventsHandler.DoEvents(); if (od.sheetvalue != null && od.sheetvalue.Count > 0) { String title = ""; foreach (KeyValuePair <string, string> kvp in od.sheetvalue) { if (kvp.Key.Equals("DRG", StringComparison.InvariantCultureIgnoreCase)) { title = kvp.Value; break; } } BOMExcelfulltitle = System.IO.Path.Combine(path, title + "_BOM.xlsx"); } } catch { } //statusText = "Generating BOM Spreadsheet... (Task 2 of 6)"; //lblpbBarContent.Content = statusText; ////pbBar.Value = (40); //pbBar.Value = pbBar.Value + 10; //DoEventsHandler.DoEvents(); statusText = "Generating Time Rollup Spreadsheet... (Task 3 of 6)"; lblpbBarContent.Content = statusText; //pbBar.Value = (60); pbBar.Value = pbBar.Value + 30; DoEventsHandler.DoEvents(); try { timeRollupExcelandXML(); } catch { } statusText = "Generating Time Rollup XML... (Task 4 of 6)"; lblpbBarContent.Content = statusText; //pbBar.Value = (70); pbBar.Value = pbBar.Value + 15; DoEventsHandler.DoEvents(); //Create Drawing PDF with BOM Excel added to Bottom statusText = "Generating Drawing PDF... (Task 5 of 6)"; lblpbBarContent.Content = statusText; pbBar.Value = pbBar.Value + (20); DoEventsHandler.DoEvents(); try { generatePDF(BOMExcelfulltitle);//Adding Excel to PDF is pending } catch { } //statusText = "Appending BOM Spreadsheet to PDF... (Task 6 of 6)"; //lblpbBarContent.Content = statusText; ////pbBar.Value = (90); //pbBar.Value = pbBar.Value + 10; //DoEventsHandler.DoEvents(); statusText = "All tasks have Completed!"; lblpbBarContent.Content = statusText; pbBar.Value = (100); DoEventsHandler.DoEvents(); }
private void Publisher_MaximumDataPublisher(object sender, SSDLPlotingPublisher.MessageArgument <double> e) { //pbStatus.Dispatcher.Invoke(() => { pbStatus.Value = 0; }); //pbStatus.Dispatcher.Invoke(() => { pbStatus.Maximum = e.Message; }); DoEventsHandler.DoEvents(); }
private void Publisher_StatusDataPublisher(object sender, SSDLPlotingPublisher.MessageArgument <string> e) { //lblStatusPublisher.Dispatcher.Invoke(() => { lblStatusPublisher.Content = e.Message; }); DoEventsHandler.DoEvents(); }