.net中取得CAD的当前图层名称

 /// <summary>
        /// 取得当前图层名称
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <returns></returns>
        public  static string  GetCurrentLayer(this Database db)
        {
            //Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //获取当前图形中所有颜色为红色的图层层名
                var CurrentLayer = (from layer in db.GetAllLayers()
                                 where layer.Id==db.Clayer
                                 select layer.Name).ToList();
                return CurrentLayer[0];
                trans.Commit();
            }
        }

上面这个办法比较麻烦,可以按下面的办法做:

        /// <summary>
        /// 取得当前图层名称
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <returns></returns>
        public  static string  GetCurrentLayer(this Database db)
        {
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                LayerTableRecord ltr = (LayerTableRecord)db.Clayer.GetObject(OpenMode.ForRead);
                return ltr.Name;
                trans.Commit();
            }
        }

.net中取得CAD的当前图层名称,布布扣,bubuko.com

.net中取得CAD的当前图层名称

上一篇:跟我一起学extjs5(13--执行菜单命令在tabPanel中显示模块)


下一篇:【转载】Web 开发中很实用的10个效果【附源码下载】