public Result createPDF(RhinoDoc doc, bool askToolHit) { RhinoApp.RunScript("Save", true); //save file before printing string fileName = Path.GetFileNameWithoutExtension(doc.Name); System.Windows.Forms.PrintDialog dlg = new PrintDialog(); //Prompt the user whether the tool hit is required on the final PDF or not if (askToolHit) { if (!MessageBoxes.Messages.showToolHitRequired()) { //If the tool hit is not required, make the tool hit layer invisible RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red); RhinoUtilities.setLayerVisibility("Tool Hit", false); } else { RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red); RhinoUtilities.setLayerVisibility("Tool Hit", true); } } else { RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red); RhinoUtilities.setLayerVisibility("Tool Hit", false); } //set the cluster sample layer to invisible RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false); if (dlg.PrinterSettings.IsValid == false) { Messages.showBullzipNotInstalled(); } else { // If Page Views is 0 if (doc.Views.GetPageViews().Count() != 0) { try { tempPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + "temp" + ".pdf"; //create a temporary pdf with panels oriPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + fileName + ".pdf"; PdfSettings pdfSettings = new PdfSettings(); //pdfSettings.PrinterName = PRINTERNAME; pdfSettings.SetValue("Output", tempPdfPath); pdfSettings.SetValue("ShowPDF", "no"); pdfSettings.SetValue("ShowSettings", "never"); pdfSettings.SetValue("ShowSaveAS", "never"); pdfSettings.SetValue("ShowProgress", "yes"); pdfSettings.SetValue("ShowProgressFinished", "no"); pdfSettings.SetValue("ConfirmOverwrite", "no"); pdfSettings.SetValue("Orientation", "portrait"); pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce); string command = string.Format("-_Print _Setup _Destination _Printer \"Bullzip PDF Printer\" _PageSize 210.000 297.00 _OutputType=Vector _Enter _View _AllLayouts _Enter _Enter _Go _Enter"); RhinoApp.RunScript(command, true); string[] pdfs = new String[2]; //create a string array to hold the locations of the pdf with panel and agreement form pdf. pdfs[0] = tempPdfPath; pdfs[1] = agreementLocation; //Uncomment the below line when adobe is purchased // RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Drawings First"); //pass the array and the target location to save the final pdf RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Watermark Only"); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error printing PDF document." + ex.Message); } } } return(Result.Success); }
/// <summary> /// Conert solid works drawing to pdf file. /// </summary> /// <param name="document">Document for building pdf</param> /// <param name="finalPath">Path to the build file</param> /// <returns></returns> private string ConvertDrwToPdf(string path) { int Errors = 0; ModelDoc2 document = SolidWorksAdapter.SldWoksAppExemplare.OpenDoc2(path, (int)swDocumentTypes_e.swDocDRAWING, false, false, true, Errors); try { ModelDocExtension swModelDocExt; PrintSpecification printSpec; Sheet sheet; swModelDocExt = document.Extension; // applied to Sheet or App, Doc... swModelDocExt.UsePageSetup = (int)swPageSetupInUse_e.swPageSetupInUse_DrawingSheet; IDrawingDoc drawingDoc = document as IDrawingDoc; PageSetup pageSetup; string[] sheetNames = drawingDoc.GetSheetNames(); PdfSettings pdfSettings = new PdfSettings(); ClearDirectory(); int tempfileIndex = 0; foreach (var sheetName in sheetNames) { //Console.WriteLine(sheetName); drawingDoc.ActivateSheet(sheetName); sheet = drawingDoc.GetCurrentSheet(); pageSetup = sheet.PageSetup; var sheetPropertis = (double[])sheet.GetProperties2(); pdfSettings.PrinterName = PrinterName; if (!Directory.Exists(TempPdfFolder)) { Directory.CreateDirectory(TempPdfFolder); } pdfSettings.SetValue("Output", string.Format(TempPdfFolder + @"\" + tempfileIndex + " temp " + sheetName + " .pdf")); tempfileIndex++; pdfSettings.SetValue("ShowPDF", "no"); pdfSettings.SetValue("ShowSettings", "never"); pdfSettings.SetValue("ShowSaveAS", "never"); pdfSettings.SetValue("ShowProgress", "no"); pdfSettings.SetValue("ShowProgressFinished", "no"); pdfSettings.SetValue("ConfirmOverwrite", "yes"); pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce); pageSetup.DrawingColor = (int)swPageSetupDrawingColor_e.swPageSetup_AutomaticDrawingColor; Orientation(pageSetup, sheetPropertis); printSpec = (PrintSpecification)swModelDocExt.GetPrintSpecification(); printSpec.ScaleMethod = (int)swPrintSelectionScaleFactor_e.swPrintCurrentSheet; printSpec.PrintToFile = false; try { swModelDocExt.PrintOut4(PrinterName, "", printSpec); System.Threading.Thread.Sleep(2000); } catch (Exception ex) { throw new Exception("Possibly not fount the Bullzip PDF Printer\n" + ex.ToString()); } } tempfileIndex = ResetIndex(); string NameAndExtension = System.IO.Path.GetFileName(path); string PathToPdfFile = PdfFolder.ToUpper() + @"\" + NameAndExtension.Replace("SLDDRW", "PDF"); // string PathToPdfFile = path.Replace("SLDDRW", "PDF"); MergePdf(PathToPdfFile); // Path to temp file return(PathToPdfFile); } catch (System.Exception exception) { throw new System.Exception("Filed buld pdf file. " + exception.ToString()); } }
///<summary>The only instance of this command.</summary> ///<param name="doc" RhinoDoc></param> ///<param name="mode" Run mode></param> ///<returns>returns sucess if doc is successfully created </returns> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.RunScript("Save", true); //save file before printing String patternFound; patternFound = extractToolHit(doc); //get the pattern if (patternFound.Contains("Round Hole 60")) //check if pattern is a round hole 60 { //set the location to round hole 60 pattern toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH60 CLUSTERS"; //Trim the pattern, so that it only reads the tool hit size patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1]; patternFound = "RH" + patternFound; } if (patternFound.Contains("Round Hole 90")) //check if pattern is a round hole 90 { //set the location to round hole 60 pattern toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH90 CLUSTERS"; //Trim the pattern, so that it only reads the tool hit size patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1]; patternFound = "RH" + patternFound; } if (patternFound.Contains("Round Hole 45")) //check if pattern is a round hole 45 { //set the location to round hole 60 pattern toolHitLocation = "W:\\Orders Current\\nOOL PDF's\\ROUND HOLE CLUSTERS\\RH45 CLUSTERS"; //Trim the pattern, so that it only reads the tool hit size patternFound = patternFound.Split(new string[] { "Round Hole " }, StringSplitOptions.None)[1]; patternFound = "RH" + patternFound; } toolHitPdfLocation = findToolHitPdf(patternFound, toolHitLocation); if (toolHitPdfLocation.Equals("Pattern not found")) { MessageBoxes.Messages.showFileNotFoundForPattern(patternFound); return(Result.Failure); } string fileName = Path.GetFileNameWithoutExtension(doc.Name); String[] nameSplit = fileName.Split(new string[] { "_" }, StringSplitOptions.None); //Add Nesting part to the file Name fileName = nameSplit[0] + "_" + nameSplit[1] + "_Nesting_" + nameSplit[2] + nameSplit[3] + "_" + nameSplit[4]; System.Windows.Forms.PrintDialog dlg = new PrintDialog(); if (dlg.PrinterSettings.IsValid == false) { Messages.showBullzipNotInstalled(); } else { // If Page Views is 0 if (doc.Views.GetPageViews().Count() != 0) { try { tempPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + "temp" + ".pdf"; //create a temporary pdf with panels oriPdfPath = Path.GetDirectoryName(doc.Path) + @"\" + fileName + ".pdf"; //set the tool hit layer and cluster sample layer to invisible RhinoUtilities.setLayerVisibility("Tool Hit", false); RhinoUtilities.setLayerVisibility("CLUSTER SAMPLE", false); PdfSettings pdfSettings = new PdfSettings(); pdfSettings.SetValue("Output", tempPdfPath); pdfSettings.SetValue("ShowPDF", "no"); pdfSettings.SetValue("ShowSettings", "never"); pdfSettings.SetValue("ShowSaveAS", "never"); pdfSettings.SetValue("ShowProgress", "yes"); pdfSettings.SetValue("ShowProgressFinished", "no"); pdfSettings.SetValue("ConfirmOverwrite", "no"); pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce); string command = string.Format("-_Print _Setup _Destination _Printer \"Bullzip PDF Printer\" _PageSize 297.000 210.00 _OutputType=Vector _Enter _View _AllLayout _Enter _Enter _Go"); RhinoApp.RunScript(command, true); string[] pdfs = new String[2]; //create a string array to hold the locations of the pdf with panel and agreement form pdf. pdfs[0] = tempPdfPath; pdfs[1] = toolHitPdfLocation; RhinoUtilities.combinePDF(oriPdfPath, pdfs, 0, 1, "Drawings Second"); //pass the array and the target location to save the final pdf } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error printing PDF document." + ex.Message); } } } return(Result.Success); }