Any comments ? ?
The using statements are from my standard template, whatever is not actually used isn't included in the build, so it's only visually an issue when the region is 'open'.
// Iterator test for Layer and Block SymbolTables
// AC2006 from MSVC#2005
// by kwb 2005Nov22
#region using declarations
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text.RegularExpressions;
//// COM Interop References
//// AutoCAD 2006 Type Library
using Autodesk.AutoCAD.Interop;
//// AXDBLib AutoCAD/ObjectDBX Common 16.0 Type Library
using Autodesk.AutoCAD.Interop.Common;
//// Assembly acdbmgd .. ObjectDBX.NET Managed Wrapper
//// Assembly acmgd .. Autocad.NET Managed Wrapper
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Colors;
// Shortcuts to the managed classes .. using the ObjectARX class prefixes
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcCm = Autodesk.AutoCAD.Colors;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcUi = Autodesk.AutoCAD.Windows;
//
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
#endregion
public class Class1120
{
[AcRx.CommandMethod("Test1120")]
public void TestCommand1120()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
using (AcDb.TransactionManager tm = db.TransactionManager)
using (Transaction tr = tm.StartTransaction())
{
LayerTable ltbl = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false);
IEnumerator ltblItem = ltbl.GetEnumerator();
while (ltblItem.MoveNext())
{
ObjectId id = (ObjectId)ltblItem.Current;
using (LayerTableRecord rec = (LayerTableRecord)tm.GetObject(id, OpenMode.ForRead))
{
ed.WriteMessage(string.Format("\nLayer Name : {0}", rec.Name));
}
}
BlockTable btbl = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
IEnumerator btblItem = btbl.GetEnumerator();
while (btblItem.MoveNext())
{
ObjectId id = (ObjectId)btblItem.Current;
using (BlockTableRecord rec = (BlockTableRecord)tm.GetObject(id, OpenMode.ForRead))
{
// string blokName = rec.Name;
// if ((blokName.Contains("*D") || blokName.Contains("*U") ) == false)
if ((rec.Name.StartsWith("*")) == false)
{
ed.WriteMessage(string.Format("\nBlock Name : {0}", rec.Name));
}
}
}
tr.Commit();
}
}
}