zoukankan      html  css  js  c++  java
  • autocad.net QQ群:193522571 cad.net添加和删除图层过滤器

    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(
    
              "
    {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(
    
              "
    Exception: {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(
    
              "
    
    Enter 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(
    
                "
    Layer filter cannot be deleted."
    
              );
    
            }
    
            else
    
            {
    
              lfc.Remove(lf);
    
              db.LayerFilters = lft;
    
    
    
    
              ListLayerFilters();
    
            }
    
          }
    
          catch(Exception ex)
    
          {
    
            ed.WriteMessage(
    
              "
    Exception: {0}",
    
              ex.Message
    
            );
    
          }
    
        }
    
      }
    
    }
  • 相关阅读:
    疫情环境下的网络学习笔记 python 5.8 数据库入门终章
    疫情环境下的网络学习笔记 python 5.7 navicat数据库,例题,sql注入
    疫情环境下的网络学习笔记 python 5.6 暂时看看
    疫情环境下的网络学习笔记 python 5.5 MYSql 表关系,外键
    疫情环境下的网络学习笔记 python 5.4 数据库基础
    疫情环境下的网络学习笔记 python 4.30 初识数据库
    疫情环境下的网络学习笔记 python 4.29 网络小项目
    XJOI 夏令营501-511测试11 游戏
    XJOI 夏令营501-511测试11 统计方案
    CF1197D Yet Another Subarray Problem
  • 原文地址:https://www.cnblogs.com/swtool/p/3770975.html
Copyright © 2011-2022 走看看