Author Topic: Adding and Removing Layer Filter difinitions  (Read 2607 times)

0 Members and 1 Guest are viewing this topic.

BuckoAk

  • Newt
  • Posts: 69
Adding and Removing Layer Filter difinitions
« on: November 01, 2009, 01:38:51 AM »
I am having trouble adding multiple filter definitions to a single filter property for autocad.
What I am looking for is a filter called "Border" with multiple filters such as "SHDH, SHDL, SHDT, SH*, SH-, SH_ and etc."
So far I can only get the program to create one filter definition.
here is the C# code I am using:

 // Creates Filter Here
LayerFilter layf1 = new LayerFilter();              

// Creates New Filter Name (property)
layf1.Name = "BORDER2";         

// Adds Filter Names (definitions)
layf1.FilterExpression = "NAME==\"SHDH\"";   

Any help would be great
« Last Edit: November 07, 2009, 01:10:39 AM by BuckoAk »

BuckoAk

  • Newt
  • Posts: 69
Re: Adding Layer Filter difinitions
« Reply #1 on: November 03, 2009, 11:49:52 PM »
Got the answer with some help

lf1.Name = "BORDER";
lf1.FilterExpression =
"NAME==\"SHBR\" OR NAME==\"SHBT\" OR NAME==\"SHBL\" OR NAME==\"SHBSCALE\"";

for those of you interested

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Adding Layer Filter difinitions
« Reply #2 on: November 04, 2009, 12:23:01 AM »


Thanks Buck

... and welcome to theSwamp.

I wondered about the validity of the wildcard SH* you were suggesting.
Can we assume that wildcard FilterExpressions are a NoNo ??

Regards
Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

BuckoAk

  • Newt
  • Posts: 69
Re: Adding and Removing Layer Filter difinitions
« Reply #3 on: November 04, 2009, 01:02:36 AM »
Thx's

You can use wildcards, the SH* was just a typo on my part. The additional code I added contained wildcards some examples are(  ~*|* and  AECC_*  )and etc., anything you can type within the layer manager you can do within the code. I did find out that you need to remove the existing layer filters first or this code will create a second group with the same names. I am trying to figure out where I am going wrong with this new code which goes along with the add layer filters. The new code is suppose to remove all layer filters and then reinstall them with the updated settings. The main code is from here.

This .net thing is new to me, I was given some direction at Through the Interface but not sure I have addressed all of the directions.
In my case I want to remove all of the existing filters and replace them with my own.
Can anyone help direct me where I am going wrong in the code below


using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.LayerManager;
namespace LayerFilters

{ //START PUBLIC CLASS

  public class Commands

  { // START COMMANDMETHOD
          
     [CommandMethod("DLF")]
     
     static public void DeleteLayerFilter()
     
    {Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    LayerFilterTree lft = db.LayerFilters;

     LayerFilterCollection lfc = db.LayerFilters.Root.NestedFilters;

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

      { LayerFilter lf = lfc;
         

      if (lf.AllowDelete)
         lfc.Remove(lf) ;
      db.LayerFilters = lft;
      }
   }
    
 } // END COMMAND METHOD

} // END PUBLIC CLASS
« Last Edit: November 07, 2009, 01:08:30 AM by BuckoAk »