该方法为LayerTable得扩展类。
/// <summary>/// 添加新的图层/// </summary>/// <param name="lt"></param>/// <param name="name">图层名称</param>/// <param name="color">图层颜色</param>/// <param name="trans"></param>public static void AddLayer(this LayerTable lt, string name, Autodesk.AutoCAD.Colors.Color color, Transaction trans) {try{//判断是否存在,不存在添加if (!lt.Has(name)){var LayerID = ObjectId.Null;LayerTableRecord ltr = new LayerTableRecord();ltr.Name = name;ltr.Color = color;lt.UpgradeOpen();LayerID = lt.Add(ltr);trans.AddNewlyCreatedDBObject(ltr, true);}}catch (Exception ex){throw;}}