• .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();
                }
            }

  • 相关阅读:
    Cocos2d Box2D之动态刚体
    Cocos2d Box2D之简介
    Cocos2d-x之物理引擎
    Cocos2d-x之UI控件简介
    Cocos2d-x之数据的处理
    My First Django Project (3)
    My First Django Project (2)
    My First Django Project
    Python 学习笔记
    利用python scrapy 框架抓取豆瓣小组数据
  • 原文地址:https://www.cnblogs.com/swtool/p/3840269.html
Copyright © 2020-2023  润新知