Code Red > .NET
Layouts
Kerry:
I've started to play with Layouts .. heading towards Plotting [expect this to be a long path ]
Anyone want to give this a run .. ?
The routine is designed to display the Names of All Layouts defined in the Document.
The initialiser may be of interest too.
--- Code - C#: ---// // KDUB// Codehimbelonga kwb@theSwamp 20070112// For AC2007: MSVS2005 #region usingdeclarations using System; //// Assembly acdbmgd .. ObjectDBX.NET Managed Wrapper//// Assembly acmgd .. Autocad.NET Managed Wrapperusing Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.Colors;#endregion #region usingAliases// Forms : MessageBox,using System.Windows.Forms;// : DictionaryEntry, using System.Collections;//using System.Collections.Generic;// For StringCollectionusing System.Collections.Specialized;// For Plottingusing Autodesk.AutoCAD.PlottingServices;//using AcDb = Autodesk.AutoCAD.DatabaseServices;using AcEd = Autodesk.AutoCAD.EditorInput;using AcRx = Autodesk.AutoCAD.Runtime;using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;using DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager; #endregion [assembly: AcRx.CommandClass(typeof(kdubTestStuff.kdubTestClass))] namespace kdubTestStuff{ /// <summary> /// Summary for kdubTestStuff /// </summary> public class kdubTestClass : AcRx.IExtensionApplication { /// <summary> /// --------------------------------------------------------------------------------------------- /// </summary> [AcRx.CommandMethod("kbLAL")] static public void listAllLayouts() { AcDb.Database db = HostApplicationServices.WorkingDatabase; AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; try { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.LayoutManager layoutMgr = AcDb.LayoutManager.Current; ed.WriteMessage("LayoutManager.CurrentLayout = " + layoutMgr.CurrentLayout + "\n"); ed.WriteMessage("LayoutManager.Count = " + layoutMgr.LayoutCount.ToString() + "\n"); using (AcDb.DBDictionary layoutDict = (AcDb.DBDictionary)tr.GetObject(db.LayoutDictionaryId, AcDb.OpenMode.ForRead)) { foreach (DictionaryEntry layoutEntry in layoutDict) { using (AcDb.Layout layoutObj = (AcDb.Layout)tr.GetObject((AcDb.ObjectId)(layoutEntry.Value), AcDb.OpenMode.ForRead)) { ed.WriteMessage("Layout.LayoutName = " + layoutObj.LayoutName + "\n"); } } } } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } /// <summary> /// --------------------------------------------------------------------------------------------- /// </summary> public void Initialize() { //Let the user know what's happening while loading your stuff AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\nLoading 'listAllLayouts' application ..."); ed.WriteMessage("\nConcept Code For AC2007, MSVS2005 :: kwb@theSwamp 20070112 ..."); ed.WriteMessage("\nUse kbLAL at command line to List all Current Layout Names\n"); } public void Terminate() { //Nothing to see here yet, move along ! } }}
... and the obligatory piccy .. :-)
Kerry:
.. and these are the Locals after the first run through the foreach loop.
I'm finding that the Locals, the Browser/Reflection is helping me make a pretty good guess regarding whats going on.
El Jefe:
Nice! works great here
I like this ...
--- Code: ---using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
--- End code ---
Hope you dont mind me borrowing stuff :-)
edit
And I do like the initialiser I’ve never seen this
El Jefe:
layoutMgr does not need to be disposed because it’s not a "new" LayoutManager right?
Kerry:
It's a good learner Dan.
Re the 'borrowing' ... whats round comes around .. I notices the concept on one of the chinese sites ages ago .. just starting to make use of it sometimes. I thought it may help me learn where everything comes from without increasing the keystroke count too much.
Navigation
[0] Message Index
[#] Next page
Go to full version