I think you have to add a layer record to database and after that change description:
Code:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Runtime;
namespace AddLayer
{
public class CmdClass
{
[CommandMethod("cmdlayer")]
public static void cmdAddLayer()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
doc.LockDocument();
kpblc_AddLayer(ref db, "test layer 1", "description1");
}
private static void kpblc_AddLayer(ref Database db, string sLayerName, string Description)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable tblLayer = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
try
{
// SymbolUtilityServices.ValidateSymbolName(sLayerName, false);
if (!(tblLayer.Has(sLayerName)))
{
// tblLayer.UpgradeOpen();
LayerTableRecord recLayer = new LayerTableRecord();
recLayer.Name = sLayerName;
// recLayer.Description = Description;
ObjectId recLayerID = tblLayer.Add(recLayer);
tr.AddNewlyCreatedDBObject(recLayer, true);
recLayer.Description = Description;
tr.Commit();
}
else
{
ed.WriteMessage("\nLayer {0} already exist", sLayerName);
}
}
catch
{
ed.WriteMessage("\nLayer {0} can't be create: Invalid symbols", sLayerName);
}
}
}
}
}