예제 #1
0
        private bool ExportPdfs()
        {
            bool res = false;

            // Checking gauge, and exporting.
            try {
                PDFArchiver pda = new PDFArchiver(ref swApp, APathSet);
                GaugeSetter gs  = new GaugeSetter(swApp, APathSet);
                gs.CheckAndUpdateGaugeNotes2();
                res = (pda.ExportPdfs());

                if (APathSet.ExportEDrw && !pda.MetalDrawing)
                {
                    res = res && pda.ExportEDrawings();
                }

                if (pda.IsTarget && pda.savedFile != string.Empty)
                {
                    string profilePath = string.Format(@"{0}{1}", Properties.Settings.Default.TargetProfilePath,
                                                       System.IO.Path.GetFileName(pda.savedFile));
                    UsefulInformationDestroyer uid_ = new UsefulInformationDestroyer(pda.savedFile, profilePath);
                    uid_.RedactUsefulDataFromDocument();
                }
            } catch (MustHaveRevException mhre) {
                swApp.SendMsgToUser2(mhre.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
            } catch (MustSaveException mse) {
                swApp.SendMsgToUser2(mse.Message,
                                     (int)swMessageBoxIcon_e.swMbStop,
                                     (int)swMessageBoxBtn_e.swMbOk);
            } catch (GaugeSetterException gEx) {
                //PDFArchiver._sendErrMessage(gEx, swApp);
                ErrMsg em = new ErrMsg(gEx);
                em.ShowDialog();
            } catch (ExportPDFException e) {
                //PDFArchiver._sendErrMessage(e, swApp);
                ErrMsg em = new ErrMsg(e);
                em.ShowDialog();
            } catch (Exception ex) {
                //PDFArchiver._sendErrMessage(ex, swApp);

                ErrMsg em = new ErrMsg(ex);
                em.ShowDialog();
            }

            return(res);
        }
예제 #2
0
 private void ExportKohlsThumbnail()
 {
     if (APathSet.ExportImg)
     {
         try {
             Thumbnailer thN        = new Thumbnailer(swApp, APathSet);
             string[]    sht_fmts   = { Properties.Settings.Default.ShtFmtPath[0], Properties.Settings.Default.ShtFmtPath[1] };
             bool[]      monochrome = { false, true };
             thN.CreateThumbnails(sht_fmts, monochrome);
         } catch (ThumbnailerException thEx) {
             ErrMsg em = new ErrMsg(thEx);
             em.ShowDialog();
         } catch (Exception ex) {
             ErrMsg em = new ErrMsg(ex);
             em.ShowDialog();
         }
     }
 }
 public void RedactUsefulDataFromDocument()
 {
     try {
         byte[] ba = _RedactUsefulDataFromDocument();
         using (FileStream fs = File.Create(target)) {
             for (int i = 0; i < ba.Length; i++)
             {
                 fs.WriteByte(ba[i]);
             }
             fs.Close();
         }
     } catch (IOException ioe) {
         System.Windows.Forms.MessageBox.Show(ioe.Message, @"Couldn't create redacted version.");
     } catch (System.Exception e) {
         using (ErrMsg er_ = new ErrMsg(e)) {
             er_.ShowDialog();
         }
     }
 }
예제 #4
0
 private void ExportThumbnail()
 {
     if (APathSet.ExportImg)
     {
         try {
             Thumbnailer thN = new Thumbnailer(swApp, APathSet);
             if (thN.assmbly)
             {
                 thN.CreateThumbnail();
                 thN.SaveAsJPG(APathSet.JPGPath);
                 thN.CloseThumbnail();
             }
         } catch (ThumbnailerException thEx) {
             ErrMsg em = new ErrMsg(thEx);
             em.ShowDialog();
         } catch (Exception ex) {
             ErrMsg em = new ErrMsg(ex);
             em.ShowDialog();
         }
     }
 }
예제 #5
0
        public void Archive()
        {
            string jsonPath = Properties.Settings.Default.defaultJSON;

            if (System.IO.File.Exists(Properties.Settings.Default.localJSON))
            {
                jsonPath = Properties.Settings.Default.localJSON;
            }

            string json    = string.Empty;
            Frame  swFrams = (Frame)swApp.Frame();

            swFrams.SetStatusBarText("Starting PDF Archiver...");
            ModelDoc2         swModel  = (ModelDoc2)swApp.ActiveDoc;
            Int32             errors   = 0;
            Int32             warnings = 0;
            swDocumentTypes_e docType;

            docType = (swDocumentTypes_e)swModel.GetType();

            if (docType != swDocumentTypes_e.swDocDRAWING)
            {
                swApp.SendMsgToUser2(string.Format("You need to have a drawing open. This is a '{0}'.", docType.ToString()),
                                     (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
            }
            else
            {
                // Saving first.
                if (APathSet.SaveFirst)
                {
                    try {
                        swFrams.SetStatusBarText("Saving ... this is usually the most time consuming part ...");
                        swModel.Save3((Int32)swSaveAsOptions_e.swSaveAsOptions_Silent, ref errors, ref warnings);
                    } catch (ExportPDFException e) {
                        //PDFArchiver._sendErrMessage(e, swApp);
                        ErrMsg em = new ErrMsg(e);
                        em.ShowDialog();
                    } catch (Exception ex) {
                        //PDFArchiver._sendErrMessage(ex, swApp);
                        ErrMsg em = new ErrMsg(ex);
                        em.ShowDialog();
                    }
                }

                if (APathSet.ExportPDF)
                {
                    if (ExportPdfs())
                    {
                        if (!swModel.GetPathName().ToUpper().Contains("METAL MANUFACTURING"))
                        {
                            bool     kohls = false;
                            LayerMgr lm    = (LayerMgr)swModel.GetLayerManager();
                            Layer    l     = (Layer)lm.GetLayer("KOHLS");
                            if (l != null)
                            {
                                if (l.Visible == true)
                                {
                                    kohls = true;
                                }
                            }
                            switch (kohls)
                            {
                            case true:
                                ExportKohlsThumbnail();
                                break;

                            case false:
                                ExportThumbnail();
                                break;

                            default:
                                break;
                            }
                        }
                        swFrams.SetStatusBarText(string.Format("Done exporting '{0}' to PDF Archive.", swModel.GetPathName().ToUpper()));
                    }
                    else
                    {
                        swApp.SendMsgToUser2("Failed to save PDF.",
                                             (int)swMessageBoxIcon_e.swMbStop,
                                             (int)swMessageBoxBtn_e.swMbOk);
                    }
                }
                swFrams.SetStatusBarText(":-(");
            }

            swFrams.SetStatusBarText(":-)");

            // Solidworks won't usually exit this macro on some machines. This seems to help.
            System.GC.Collect(0, GCCollectionMode.Forced);
        }