//https://blog.csdn.net/qq_21489689?t=1
[CommandMethod("CREATELY")]
public void CreateLayer()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;//获取当前数据库
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
//以读的方式打开图层表
LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,OpenMode.ForRead) as LayerTable;
string sLayerName = "Layer Name";//设定一个图层名称
if (acLyrTbl.Has(sLayerName) == false)
{
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);// 指定图层颜色
acLyrTblRec.Name = sLayerName;// 指定图层名称
acLyrTbl.UpgradeOpen();//修改图层打开方式为写
acLyrTbl.Add(acLyrTblRec);//将新图层追加到图层表
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
}
}
acTrans.Commit();
}
}