using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.ApplicationServices; namespace ClassLibrary { public class YdsClass { public YdsClass() { } [CommandMethod("PurgeLayer")] static public void test() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction actrans = db.TransactionManager.StartTransaction()) { LayerTable ly; DimStyleTable dy; dy = actrans.GetObject(db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable; ly = actrans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable; ObjectIdCollection ids = new ObjectIdCollection(); foreach (ObjectId id in ly) { ids.Add(id); } foreach (ObjectId id in dy) { ids.Add(id); } db.Purge(ids); foreach (ObjectId id in ids) { SymbolTableRecord rec; rec = actrans.GetObject(id, OpenMode.ForWrite) as SymbolTableRecord; try { rec.Erase(true); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Application.ShowAlertDialog(ex.ToString()); } } actrans.Commit(); } } [CommandMethod("RenameLayer")] static public void text1() { Document dc = Application.DocumentManager.MdiActiveDocument; Database db = dc.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) { LayerTable ly; ly = trans.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable; LayerTableRecord lr; lr = trans.GetObject(ly["0"], OpenMode.ForRead).Clone() as LayerTableRecord; lr.Name = "Mylayer"; ly.Add(lr); trans.AddNewlyCreatedDBObject(lr, true); trans.Commit(); } } } }