/// <summary>
 /// 激活图层(取消冻结、锁定、隐藏)
 /// </summary>
 /// <param name="LayerName"></param>
 /// <returns></returns>
 public bool ActivationLayer(string LayerName = "")
 {
     try
     {
         using (Transaction tran = database.TransactionManager.StartTransaction())
         {
             foreach (ObjectId LayerId in LayerTbl)
             {
                 LayerTableRecord Layer = LayerId.GetObject(OpenMode.ForWrite) as LayerTableRecord;
                 if (string.IsNullOrWhiteSpace(LayerName) || Layer.Name == LayerName)
                 {
                     Layer.IsLocked = false;
                     Layer.IsHidden = false;
                     Layer.IsFrozen = false;
                 }
                 Layer.DowngradeOpen();
             }
             tran.Commit();
         }
     }
     catch (Exception ex)
     {
         Logger.log("ActivationLayer", ex.Message);
     }
     return(false);
 }
示例#2
0
 /// <summary>
 /// 设置图层rgb颜色
 /// </summary>
 /// <param name="db"></param>
 /// <param name="layerName"></param>
 /// <param name="RedColor">R</param>
 /// <param name="GreenColor">G</param>
 /// <param name="BlueColor">B</param>
 /// <returns></returns>
 public static bool SetLayerColor(this Database db, string layerName, int RedColor, int GreenColor, int BlueColor)
 {
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
         if (!lt.Has(layerName))
         {
             return(false);
         }
         ObjectId         layerId = lt[layerName];
         LayerTableRecord ltr     = (LayerTableRecord)layerId.GetObject(OpenMode.ForWrite);
         ltr.Color = Color.FromRgb(Convert.ToByte(RedColor), Convert.ToByte(GreenColor), Convert.ToByte(BlueColor));
         ltr.DowngradeOpen();
         trans.Commit();
     }
     return(true);
 }
示例#3
0
 /// <summary>
 /// 设置图层索引颜色
 /// </summary>
 /// <param name="db"></param>
 /// <param name="layerName">图层名</param>
 /// <param name="colorIndex">索引颜色</param>
 /// <returns></returns>
 public static bool SetLayerColor(this Database db, string layerName, int colorIndex)
 {
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
         if (!lt.Has(layerName))
         {
             return(false);
         }
         ObjectId         layerId = lt[layerName];
         LayerTableRecord ltr     = (LayerTableRecord)layerId.GetObject(OpenMode.ForWrite);
         ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, (short)colorIndex);
         ltr.DowngradeOpen();
         trans.Commit();
     }
     return(true);
 }
示例#4
0
        /// <summary>
        /// 设置图层的颜色
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="layerName">图层名</param>
        /// <param name="colorIndex">颜色索引</param>
        /// <returns>如果成功设置图层颜色,则返回true,否则返回false</returns>
        public static bool SetLayerColor(this Database db, string layerName, short colorIndex)
        {
            //打开层表
            LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);

            //如果不存在名为layerName的图层,则返回
            if (!lt.Has(layerName))
            {
                return(false);
            }
            ObjectId layerId = lt[layerName];//获取名为layerName的层表记录的Id
            //以写的方式打开名为layerName的层表记录
            LayerTableRecord ltr = (LayerTableRecord)layerId.GetObject(OpenMode.ForWrite);

            //设置图层的颜色
            ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex);
            ltr.DowngradeOpen(); //为了安全,将图层的状态切换为读
            return(true);        //设置图层颜色成功
        }
 /// <summary>
 /// 设置图层状态
 /// </summary>
 /// <param name="LayerStateList"></param>
 /// <returns></returns>
 public bool SetLayerStates(List <LayerState> LayerStateList)
 {
     try
     {
         using (Transaction tran = database.TransactionManager.StartTransaction()) {
             foreach (LayerState State in LayerStateList)
             {
                 LayerTableRecord Layer = State.LayerId.GetObject(OpenMode.ForWrite) as LayerTableRecord;
                 Layer.IsLocked = State.IsLocked;
                 Layer.IsHidden = State.IsHidden;
                 Layer.IsFrozen = State.IsFrozen;
                 Layer.DowngradeOpen();
             }
             tran.Commit();
         }
     }
     catch (Exception ex) {
         Logger.log("SetLayerStates", ex.Message);
     }
     return(false);
 }
示例#6
0
        public static ObjectId AddLayer(Database db, string layerName, short LayerColorIndex, string LineTypeName, string Description)//封装添加图层方法
        {
            LayerTable layerTable = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);

            if (!layerTable.Has(layerName))
            {
                LayerTableRecord layer = new LayerTableRecord();
                layer.Name = layerName;
                ColorMethod method = ColorMethod.ByLayer;
                layer.Color = Color.FromColorIndex(method, LayerColorIndex);
                var lt = (LinetypeTable)db.LinetypeTableId.GetObject(OpenMode.ForRead);
                LoadLineType();
                var id = lt[LineTypeName];
                layer.LinetypeObjectId = id;
                layer.Description      = Description;
                layerTable.UpgradeOpen();
                layerTable.Add(layer);
                db.TransactionManager.AddNewlyCreatedDBObject(layer, true);
                layer.DowngradeOpen();
            }
            return(layerTable[layerName]);
        }