using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
#pragma warning disable 0618
[assembly: CommandClass(typeof(Rivilis.AddLayerDescription))]
namespace Rivilis
{
public class AddLayerDescription
{
const string LayerName = "Rivilis_Layer";
const string LayerDescription = "Rivilis Layer";
[CommandMethod("AddDescription")]
public void AddDescription()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Database db = doc.Database;
using (SymbolTable st = db.LayerTableId.Open(OpenMode.ForRead) as SymbolTable) {
LayerTable lt = st.IncludingErased as LayerTable;
if (lt.Has(LayerName)) {
using (LayerTableRecord ltr = lt[LayerName].Open(OpenMode.ForWrite) as LayerTableRecord) {
ltr.Description = LayerDescription;
}
} else {
using (LayerTableRecord ltr = new LayerTableRecord()) {
ltr.Name = LayerName;
lt.UpgradeOpen();
lt.Add(ltr);
lt.DowngradeOpen();
ltr.Description = LayerDescription;
}
}
}
}
}
}