视频剪辑软件 JavaSE USB串口通信 json firebase oop deployment printing yii2 vue网页 vue教学视频 easyui视频 直销系统源码 mysql安装后怎么使用 matlab向量的模 xcode打包 mysql汉化包 jquery validate 后台管理网站模板 python3网络编程 python文件写入 java中的对象 java初级教程 java的集合框架 linux启动 摩斯电码翻译器 刺激战场脚本 maxtoc4d 剑三醉猿 spss22安装教程 jq改变css样式 看图软件cad 草图大师版本转换器 mix2s拆机 ps祛痘 画图橡皮擦怎么放大 淘宝店铺会员 mxf是什么格式 ansys安装 pdf分割合并工具
当前位置: 首页 > 学习教程  > 编程学习

autocad.net QQ群:193522571 cad.net添加和删除图层过滤器

2021/1/9 1:53:31 文章标签: cad图层无法删除

cad.net添加和删除图层过滤器 using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.LayerManager;namespace LayerFilters{public class Command…

 

cad.net添加和删除图层过滤器 using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.LayerManager;




namespace LayerFilters

{

  public class Commands

  {

    [CommandMethod("LLFS")]

    static public void ListLayerFilters()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;




      // List the nested layer filters




      LayerFilterCollection lfc =

        db.LayerFilters.Root.NestedFilters;




      for (int i = 0; i < lfc.Count; ++i)

      {

        LayerFilter lf = lfc[i];

        ed.WriteMessage(

          "\n{0} - {1} (can{2} be deleted)",

          i + 1,

          lf.Name,

          (lf.AllowDelete ? "" : "not")

        );

      }

    }




    [CommandMethod("CLFS")]

    static public void CreateLayerFilters()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;




      try

      {

        // Get the existing layer filters

        // (we will add to them and set them back)




        LayerFilterTree lft =

          db.LayerFilters;

        LayerFilterCollection lfc =

          lft.Root.NestedFilters;




        // Create three new layer filters




        LayerFilter lf1 = new LayerFilter();

        lf1.Name = "Unlocked Layers";

        lf1.FilterExpression = "LOCKED==\"False\"";




        LayerFilter lf2 = new LayerFilter();

        lf2.Name = "White Layers";

        lf2.FilterExpression = "COLOR==\"7\"";




        LayerFilter lf3 = new LayerFilter();

        lf3.Name = "Visible Layers";

        lf3.FilterExpression =

          "OFF==\"False\" AND FROZEN==\"False\"";




        // Add them to the collection




        lfc.Add(lf1);

        lfc.Add(lf2);

        lfc.Add(lf3);




        // Set them back on the Database




        db.LayerFilters = lft;




        // List the layer filters, to see the new ones




        ListLayerFilters();

      }

      catch (Exception ex)

      {

        ed.WriteMessage(

          "\nException: {0}",

          ex.Message

        );

      }

    }




    [CommandMethod("DLF")]

    static public void DeleteLayerFilter()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;




      ListLayerFilters();




      try

      {

        // Get the existing layer filters

        // (we will add to them and set them back)




        LayerFilterTree lft =

          db.LayerFilters;

        LayerFilterCollection lfc =

          lft.Root.NestedFilters;




        // Prompt for the index of the filter to delete




        PromptIntegerOptions pio =

          new PromptIntegerOptions(

          "\n\nEnter index of filter to delete"

          );

        pio.LowerLimit = 1;

        pio.UpperLimit = lfc.Count;




        PromptIntegerResult pir =

          ed.GetInteger(pio);




        // Get the selected filter




        LayerFilter lf = lfc[pir.Value - 1];




        // If it's possible to delete it, do so




        if (!lf.AllowDelete)

        {

          ed.WriteMessage(

            "\nLayer filter cannot be deleted."

          );

        }

        else

        {

          lfc.Remove(lf);

          db.LayerFilters = lft;




          ListLayerFilters();

        }

      }

      catch(Exception ex)

      {

        ed.WriteMessage(

          "\nException: {0}",

          ex.Message

        );

      }

    }

  }

}

 

转载于:https://www.cnblogs.com/swtool/p/3770975.html


本文链接: http://www.dtmao.cc/news_show_1100052.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?