static public void Plan2LayTransExport() { try { #if BRX_APP return; #else _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { //_AcWnd.SaveFileDialog sfd = new _AcWnd.SaveFileDialog("Excel-Datei", "", "xlsx","LayTransSave", _AcWnd.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension); //System.Windows.Forms.DialogResult dr = sfd.ShowDialog(); //if (dr != System.Windows.Forms.DialogResult.OK) return; Engine engine = new Engine(); var ok = engine.ExcelExport(); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler beim Export!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Der Excel-Export wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTransExport aufgetreten! {0}", ex.Message)); } }
static public void Plan2CenterBlockSelBlock() { try { if (!OpenPalette()) { return; } var opts = Globs.TheOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nBlock wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.BlockReference br = obj as _AcDb.BlockReference; if (br == null) { br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br == null) { return; } } opts.SetBlockname(br.Name); tr.Commit(); } } } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockSelBlock aufgetreten! {0}", ex.Message)); } }
static public void Plan2LayTransExportBulk() { try { #if BRX_APP return; #else log.Info("----------------------------------------------------------------------------------"); log.Info("Plan2LayTransExportBulk"); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { string dirName = string.Empty; using (var folderBrowser = new System.Windows.Forms.FolderBrowserDialog()) { folderBrowser.Description = "Verzeichnis mit Zeichnungen für den Layerexport"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowser.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } dirName = folderBrowser.SelectedPath; } //dirName = @"D:\Plan2\Data\Plan2PlotToDwf"; Engine engine = new Engine(); var ok = engine.ExcelExport(dirName); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler beim Plan2LayTransExportBulk!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Der Excel-Export wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTransExportBulk aufgetreten! {0}", ex.Message)); } }
static public void Plan2LayTrans() { try { #if BRX_APP return; #else _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; // First let's use the editor method, GetFileNameForOpen() _AcEd.PromptOpenFileOptions opts = new _AcEd.PromptOpenFileOptions("Excel-Datei für Layer-Infos"); opts.Filter = "Excel (*.xlsx)|*.xlsx|Excel alt (*.xls)|*.xls"; _AcEd.PromptFileNameResult pr = ed.GetFileNameForOpen(opts); if (pr.Status != _AcEd.PromptStatus.OK) { return; } //_AcWnd.OpenFileDialog ofd = new _AcWnd.OpenFileDialog("Excel-Datei", "", "xlsx", "LayTrans", _AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension); //System.Windows.Forms.DialogResult dr = ofd.ShowDialog(); //if (dr != System.Windows.Forms.DialogResult.OK) return; string fileName = pr.StringResult; Engine engine = new Engine(); var ok = engine.LayTrans(fileName); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in LayTrans!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "LayTrans wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTrans aufgetreten! {0}", ex.Message)); } }
static public void Plan2AutoIdExcelExport() { try { #if BRX_APP return; #else if (!OpenAutoIdPalette()) { return; } var opts = Globs.TheAutoIdOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { Engine engine = new Engine(opts); var ok = engine.ExcelExport(); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Nicht alle Blöcke haben die gleichen Attribute (siehe %temp%\\plan2.log)")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Der Excel-Export wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdExcelExport aufgetreten! {0}", ex.Message)); } }
static public void Plan2AutoIdVergabe() { try { if (!OpenAutoIdPalette()) { return; } var opts = Globs.TheAutoIdOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { Engine engine = new Engine(opts); engine.AssignIds(); } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdVergabe aufgetreten! {0}", ex.Message)); } }
public void Plan2CenterBlockDelErrSyms() { try { if (!OpenPalette()) { return; } var opts = Globs.TheOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { CenterRaumBlock crb = new CenterRaumBlock(); crb.DelErrSyms(doc); } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockDelErrSyms aufgetreten! {0}", ex.Message)); } }
static public void Plan2PlotToDwfBulk() { _Doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = _Doc.Database; _Editor = _Doc.Editor; _NrPlots = 0; _NrPlotsAll = 0; _MultipleLayoutNames = false; _LayoutNames.Clear(); try { log.Info("----------------------------------------------------------------------------------"); log.Info("Plan2PlotToDwfBulk"); string dirName = string.Empty; using (var folderBrowser = new System.Windows.Forms.FolderBrowserDialog()) { folderBrowser.Description = "Verzeichnis mit Zeichnungen für den DWF-Plot"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowser.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } dirName = folderBrowser.SelectedPath; } //dirName = @"D:\Plan2\Data\Plan2PlotToDwf"; log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnungen unter '{0}' werden als DWF geplottet.", dirName)); var files = System.IO.Directory.GetFiles(dirName, "*.dwg", System.IO.SearchOption.AllDirectories); foreach (var fileName in files) { 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; _Editor = _Doc.Editor; using (DocumentLock acLckDoc = _Doc.LockDocument()) { _NrPlots = 0; // main part if (!PlotInLayouts()) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler beim Plotten in Zeichnung '{0}'!", fileName); log.Warn(msg); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Anzahl erzeugter Plots: {0} in Zeichnung '{1}'.", _NrPlots.ToString(), fileName); log.Info(msg); } _NrPlotsAll += _NrPlots; } _Doc.CloseAndDiscard(); } string add = string.Empty; if (_MultipleLayoutNames) { add = "\n" + "Mehrfache Layoutnamen! (siehe Log-Datei)."; } string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl erzeugter Plots: {0}{1}", _NrPlotsAll.ToString(), add); System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2PlotToDwf"); } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "{0}", ex.Message); System.Windows.Forms.MessageBox.Show(msg, "Plan2PlotToDwfBulk"); } }
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 Plan2AutoIdAssignments() { try { if (!OpenAutoIdPalette()) { return; } var opts = Globs.TheAutoIdOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif SetAssignmentsDict(); _AutoIdPalette.SetLvZuweisungen(); //bool attSelected = false; //while (!attSelected) //{ // PromptNestedEntityOptions peo = new PromptNestedEntityOptions("\nZu-Raum-ID-Attribut wählen: "); // PromptNestedEntityResult per = ed.GetNestedEntity(peo); // if (per.Status == _AcEd.PromptStatus.OK) // { // using (var tr = doc.TransactionManager.StartTransaction()) // { // DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); // _AcDb.AttributeReference attRef = obj as _AcDb.AttributeReference; // if (attRef != null) // { // attSelected = true; // opts.SetZuRaumIdAtt(attRef.Tag); // } // else // { // ed.WriteMessage("\nDas gewählte Element ist kein Attribut."); // } // tr.Commit(); // } // } // else // { // break; // } //} } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdAssignments aufgetreten! {0}", ex.Message)); } }
static public void Plan2AutoIdSelPolygonLayer() { try { if (!OpenAutoIdPalette()) { return; } var opts = Globs.TheAutoIdOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif _AcEd.PromptNestedEntityOptions peo = new _AcEd.PromptNestedEntityOptions("\nPolylinie wählen: "); //peo.SetRejectMessage("\nDas gewählte Element ist keine Polylinie."); //peo.AddAllowedClass(typeof(Polyline), true); //peo.AddAllowedClass(typeof(Polyline2d), true); //peo.AddAllowedClass(typeof(Polyline3d), true); _AcEd.PromptEntityResult per = ed.GetNestedEntity(peo); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.Entity ent = obj as _AcDb.Entity; if (ent != null) { if (ent is _AcDb.Polyline || ent is _AcDb.Polyline2d || ent is _AcDb.Polyline3d) { opts.SetPolygonLayer(Engine.RemoveXRefPart(ent.Layer)); } else { ed.WriteMessage("\nDas gewählte Element ist keine Polylinie."); } } tr.Commit(); } } } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdSelPolygonLayer aufgetreten! {0}", ex.Message)); } }
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"); } }