public static void CreateLayout(string name) { _AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database acCurDb = acDoc.Database; using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction()) { // Reference the Layout Manager _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current; // Create the new layout with default settings _AcDb.ObjectId objID = acLayoutMgr.CreateLayout(name); // Open the layout _AcDb.Layout layout = trans.GetObject(objID, _AcDb.OpenMode.ForRead) as _AcDb.Layout; // Set the layout current if it is not already if (layout.TabSelected == false) { acLayoutMgr.CurrentLayout = layout.LayoutName; } // Output some information related to the layout object acDoc.Editor.WriteMessage("\nTab Order: " + layout.TabOrder + "\nTab Selected: " + layout.TabSelected + "\nBlock Table Record ID: " + layout.BlockTableRecordId.ToString()); // Save the changes made trans.Commit(); } }
private static bool SetPlotSettings(string loName, string device, string pageSize, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?plotRotation) { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; var layoutId = layoutMgr.GetLayoutId(loName); if (!layoutId.IsValid) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Layout '{0}' existiert nicht!", loName)); } using (var tr = db.TransactionManager.StartTransaction()) { var layout = (_AcDb.Layout)tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite); layout.SetPlotSettings(device, pageSize, styleSheet, scaleNumerator, scaleDenominator, plotRotation); tr.Commit(); } return(true); }
private static bool PlotInLayouts() { var ok = true; _AcAp.Application.SetSystemVariable("BACKGROUNDPLOT", 0); using (_Tr = _Db.TransactionManager.StartTransaction()) { var layouts = _Tr.GetObject(_Db.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; foreach (var layoutDe in layouts) { //_AcDb.ObjectId layoutId = layManager.GetLayoutId(layManager.CurrentLayout); var layoutId = layoutDe.Value; var layoutObj = (_AcDb.Layout)_Tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite); var loNameUC = layoutObj.LayoutName.ToUpperInvariant(); if (string.Compare(loNameUC, "MODEL", StringComparison.OrdinalIgnoreCase) == 0 || loNameUC.StartsWith("X_", StringComparison.OrdinalIgnoreCase)) { continue; } var fileName = _Doc.Name; var dwgName = Path.GetFileNameWithoutExtension(fileName); var dirName = Path.GetDirectoryName(fileName); //var dwfName = Path.Combine(dirName, dwgName + "_" + RemoveInvalidCharacters(lo.LayoutName) + ".dwf"); var dwfName = Path.Combine(dirName, RemoveInvalidCharacters(layoutObj.LayoutName) + ".dwf"); log.InfoFormat("Ausgabedateiname: {0}", dwfName); var dwfNameUC = dwfName.ToUpperInvariant(); if (_LayoutNames.Contains(dwfNameUC)) { var msg = string.Format("Dwf kann nicht exportiert werden, da dieses schon aus einer Zeichnung exportiert wurde! {0}", dwfName); log.Warn(msg); _Editor.WriteMessage("\n" + msg); _MultipleLayoutNames = true; ok = false; continue; } else { _LayoutNames.Add(dwfNameUC); } if (layoutObj.TabSelected == false) { _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current; acLayoutMgr.CurrentLayout = layoutObj.LayoutName; } if (!PlotDwf(layoutObj, dwfName)) { ok = false; } } _Tr.Commit(); } return(ok); }
public PRINT_command_v2(ref _CONNECTION c) { _c = c; local_stats = new List <_Area_v2>(); engine = _Pl.PlotFactory.CreatePublishEngine(); layoutManager = _Db.LayoutManager.Current; }
public static void Plan2ReplaceInLayoutNames() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = doc.Database; _AcEd.Editor ed = doc.Editor; _OldText = string.Empty; _NewText = string.Empty; try { var layoutNames = Plan2Ext.Layouts.GetLayoutNames(); layoutNames = layoutNames.Where(x => string.Compare(x, "Model", StringComparison.OrdinalIgnoreCase) != 0).ToList(); if (!GetOldText(ed)) { return; } if (!GetNewText(ed)) { return; } _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); } } _Tr.Commit(); } } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ReplaceInLayoutNames): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ReplaceInLayoutNames"); } }
public void renameLayout(string find, string replace) { List <string> layouts = new List <string>(); _Db.DBDictionary lays = _c.trans.GetObject(_c.db.LayoutDictionaryId, _Db.OpenMode.ForWrite) as _Db.DBDictionary; foreach (_Db.DBDictionaryEntry item in lays) { if (item.Key.Contains(find)) { string name = item.Key; layouts.Add(name); } } if (layouts.Count > 0) { _Db.LayoutManager lm = _Db.LayoutManager.Current; foreach (string lay in layouts) { string newname = lay.Replace(find, replace); lm.RenameLayout(lay, newname); } string randomName = generateRandomString(40); _Db.ObjectId id = lm.GetLayoutId(randomName); if (!id.IsValid) { id = lm.CreateLayout(randomName); } lm.DeleteLayout(randomName); lm.Dispose(); } }
/// <summary> /// Creates a layout with the specified name and optionally makes it current. /// </summary> /// <param name="name">The name of the viewport.</param> /// <param name="select">Whether to select it.</param> /// <returns>The ObjectId of the newly created viewport.</returns> public static _AcDb.ObjectId CreateAndMakeLayoutCurrent( this _AcDb.LayoutManager lm, string name, bool select = true ) { // First try to get the layout var id = lm.GetLayoutId(name); // If it doesn't exist, we create it if (!id.IsValid) { id = lm.CreateLayout(name); } // And finally we select it if (select) { lm.CurrentLayout = name; } return(id); }
//[_AcTrx.CommandMethod("ListLayouts")] public static void ListLayoutsMethod() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; ed.WriteMessage ( String.Format ( "{0}Active Layout is : {1}", Environment.NewLine, layoutMgr.CurrentLayout ) ); ed.WriteMessage ( String.Format ( "{0}Number of Layouts: {1}{0}List of all Layouts:", Environment.NewLine, layoutMgr.LayoutCount ) ); using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { _AcDb.DBDictionary layoutDic = tr.GetObject( db.LayoutDictionaryId, _AcDb.OpenMode.ForRead, false ) as _AcDb.DBDictionary; foreach (_AcDb.DBDictionaryEntry entry in layoutDic) { _AcDb.ObjectId layoutId = entry.Value; _AcDb.Layout layout = tr.GetObject( layoutId, _AcDb.OpenMode.ForRead ) as _AcDb.Layout; ed.WriteMessage( String.Format( "{0}--> {1}", Environment.NewLine, layout.LayoutName ) ); } tr.Commit(); } }
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"); } }