private DrawingDoc CreerPlan(String materiau, Double epaisseur) { String Fichier = String.Format("{0}{1} - Ep{2}", String.IsNullOrWhiteSpace(RefFichier) ? "" : RefFichier + " - ", materiau.eGetSafeFilename("-"), epaisseur.ToString().Replace('.', ',') ).Trim(); if (DicDessins.ContainsKey(Fichier)) { return(DicDessins[Fichier]); } if (MajPlans) { var di = new DirectoryInfo(DossierDVP); var NomFichierExt = Fichier + eTypeDoc.Dessin.GetEnumInfo <ExtFichier>(); var r = di.GetFiles(NomFichierExt, SearchOption.TopDirectoryOnly); if (r.Length > 0) { int Erreur = 0, Warning = 0; DrawingDoc dessin = App.Sw.OpenDoc6(Path.Combine(DossierDVP, NomFichierExt), (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Erreur, ref Warning).eDrawingDoc(); DicDessins.Add(Fichier, dessin); return(dessin); } } DrawingDoc Dessin = Sw.eCreerDocument(DossierDVP, Fichier, eTypeDoc.Dessin, CONSTANTES.MODELE_DE_DESSIN_LASER).eDrawingDoc(); Dessin.eFeuilleActive().SetName(Fichier); DicDessins.Add(Fichier, Dessin); ModelDoc2 mdl = Dessin.eModelDoc2(); LayerMgr LM = mdl.GetLayerManager(); LM.AddLayer("GRAVURE", "", 1227327, (int)swLineStyles_e.swLineCONTINUOUS, (int)swLineWeights_e.swLW_LAYER); LM.AddLayer("QUANTITE", "", 1227327, (int)swLineStyles_e.swLineCONTINUOUS, (int)swLineWeights_e.swLW_LAYER); ModelDocExtension ext = mdl.Extension; ext.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swFlatPatternOpt_ShowFixedFace, 0, false); ext.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swShowSheetMetalBendNotes, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, AfficherNotePliage); TextFormat tf = ext.GetUserPreferenceTextFormat(((int)(swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat)), 0); tf.CharHeight = TailleInscription / 1000.0; ext.SetUserPreferenceTextFormat((int)swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat, 0, tf); return(Dessin); }
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); }