static public void Plan2SetCtbInLayoutsBulk() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = doc.Database; _AcEd.Editor ed = doc.Editor; _CtbName = string.Empty; _DwgsWrongCtb.Clear(); _NrCtbs = 0; List <string> saveNotPossible = new List <string>(); try { log.Info("----------------------------------------------------------------------------------"); log.Info("Plan2SetCtbInLayoutsBulk"); using (DocumentLock acLckDoc = doc.LockDocument()) { if (!GetCtbName(ed)) { return; } } string dirName = string.Empty; using (var folderBrowser = new System.Windows.Forms.FolderBrowserDialog()) { folderBrowser.Description = "Verzeichnis mit Zeichnungen für die Umbenennung der Layouts"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowser.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } dirName = folderBrowser.SelectedPath; } log.Info(string.Format(CultureInfo.CurrentCulture, "CTB '{0}' wird gesetzt in Zeichnungen unter '{1}'.", _CtbName, dirName)); var files = System.IO.Directory.GetFiles(dirName, "*.dwg", System.IO.SearchOption.AllDirectories); foreach (var fileName in files) { SetReadOnlyAttribute(fileName, false); bool ok = false; log.Info("----------------------------------------------------------------------------------"); log.Info(string.Format(CultureInfo.CurrentCulture, "Öffne Zeichnung {0}", fileName)); _AcAp.Application.DocumentManager.Open(fileName, false); doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = doc.Database; //Lock the new document using (DocumentLock acLckDoc = doc.LockDocument()) { // main part ok = SetCtbInLayouts(); } if (ok) { log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnung speichern und schließen: {0}", fileName)); try { doc.CloseAndSave(fileName); } catch (System.Exception ex) { log.Warn(string.Format(CultureInfo.CurrentCulture, "Zeichnung konnte nicht gespeichert werden! {0}. {1}", fileName, ex.Message)); saveNotPossible.Add(fileName); doc.CloseAndDiscard(); } } else { _DwgsWrongCtb.Add(fileName); log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnung schließen ohne zu speichern da keine CTBs nicht geändert wurden: {0}", fileName)); doc.CloseAndDiscard(); } } if (saveNotPossible.Count > 0) { var names = saveNotPossible.Select(x => System.IO.Path.GetFileName(x)).ToArray(); var allNames = string.Join(", ", names); System.Windows.Forms.MessageBox.Show(string.Format("Folgende Zeichnungen konnen nicht gespeichert werden: {0}", allNames), "Plan2SetCtbInLayoutsBulk"); } ShowResultMessage(dirName.ToUpperInvariant()); } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "{0}", ex.Message); System.Windows.Forms.MessageBox.Show(msg, "Plan2SetCtbInLayoutsBulk"); } }
static public void Plan2ReplaceInLayoutNamesBulk() { try { log.Info("----------------------------------------------------------------------------------"); log.Info("Plan2ReplaceInLayoutNamesBulk"); string dirName = null; _NrOfReplacedTexts = 0; _OldText = ""; _NewText = ""; List <string> saveNotPossible = new List <string>(); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; if (!GetOldText(ed)) { return; } if (!GetNewText(ed)) { return; } using (var folderBrowser = new System.Windows.Forms.FolderBrowserDialog()) { folderBrowser.Description = "Verzeichnis mit Zeichnungen für die Umbenennung der Layouts"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowser.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } dirName = folderBrowser.SelectedPath; } log.Info(string.Format(CultureInfo.CurrentCulture, "Ersetzung: '{0}' -> '{1}'.", _OldText, _NewText)); var files = System.IO.Directory.GetFiles(dirName, "*.dwg", System.IO.SearchOption.AllDirectories); foreach (var fileName in files) { SetReadOnlyAttribute(fileName, false); bool ok = false; log.Info("----------------------------------------------------------------------------------"); log.Info(string.Format(CultureInfo.CurrentCulture, "Öffne Zeichnung {0}", fileName)); _AcAp.Application.DocumentManager.Open(fileName, false); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; //Lock the new document using (DocumentLock acLckDoc = doc.LockDocument()) { // main part var layoutNames = Plan2Ext.Layouts.GetLayoutNames(); layoutNames = layoutNames.Where(x => string.Compare(x, "Model", StringComparison.OrdinalIgnoreCase) != 0).ToList(); _Tr = db.TransactionManager.StartTransaction(); using (_Tr) { _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; foreach (var name in layoutNames) { bool changed; var newT = ReplaceTexts(name, out changed); if (changed) { layoutMgr.RenameLayout(name, newT); _NrOfReplacedTexts++; ok = true; } } _Tr.Commit(); } } if (ok) { log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnung speichern und schließen: {0}", fileName)); try { doc.CloseAndSave(fileName); } catch (System.Exception ex) { log.Warn(string.Format(CultureInfo.CurrentCulture, "Zeichnung konnte nicht gespeichert werden! {0}. {1}", fileName, ex.Message)); saveNotPossible.Add(fileName); doc.CloseAndDiscard(); } } else { log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnung schließen ohne zu speichern da keine Layouts geändert wurden: {0}", fileName)); doc.CloseAndDiscard(); } } if (saveNotPossible.Count > 0) { var names = saveNotPossible.Select(x => System.IO.Path.GetFileName(x)).ToArray(); var allNames = string.Join(", ", names); System.Windows.Forms.MessageBox.Show(string.Format("Folgende Zeichnungen konnen nicht gespeichert werden: {0}", allNames), "Plan2ReplaceInLayoutNamesBulk"); } ShowResultMessage(dirName.ToUpperInvariant()); } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "{0}", ex.Message); System.Windows.Forms.MessageBox.Show(msg, "Plan2ReplaceInLayoutNamesBulk"); } }