Author Topic: XREF LAYER FILTER  (Read 1262 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1851
XREF LAYER FILTER
« on: April 16, 2014, 12:24:41 PM »
I have seen other people have looked for the same thing,  I want to have a resident layer filter that is the same as choosing the xref filter and inverting it.
Unfortunately cad doesn't save that setting and on reopening the dwg you are left w/ seeing all the xref layers.
The below code makes a filter that is  ~*|*  under the name  column of the LAYER filter properties box. However it doesn't work properly.
If I make a new filter in cad using  ~*|*   in the same place it does work.
Perhaps I am getting the syntax wrong.
Hopefully someone has already solved this.



Code - C#: [Select]
  1.         [CommandMethod("NoXrefLayers")]
  2.         static public void NoXrefLayers()
  3.         {
  4.             Document doc = acadApp.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.             bool bXref = false;
  8.             LayerFilterTree lft = db.LayerFilters;
  9.             LayerFilterCollection lfc = db.LayerFilters.Root.NestedFilters;
  10.  
  11.             for (int i = 0; i < lfc.Count; ++i)
  12.             {
  13.                 LayerFilter lf = lfc[i];
  14.                 ed.WriteMessage(Environment.NewLine + lf.FilterExpression);
  15.                 if (lf.Name == "Xref")  //only shows up if there is an xref          
  16.                     bXref = true;                
  17.                 else if(lf.Name=="no_xref_layers")
  18.                 {
  19.                     LayerFilterTree lyrTree2 = new LayerFilterTree(lft.Root, lf);
  20.                     HostApplicationServices.WorkingDatabase.LayerFilters = lyrTree2;
  21.                     return;
  22.                 }              
  23.             }
  24.             if (!bXref) return;
  25.  
  26.             LayerFilter lfXref = new LayerFilter();
  27.             lfXref = new LayerFilter();
  28.             lfXref.Name = "no_xref_layers";
  29.             lfXref.FilterExpression = "NAME!=\"*|*\"";
  30.            
  31.    
  32.             lft.Root.NestedFilters.Add(lfXref);
  33.             lft = new LayerFilterTree(lft.Root, lfXref);
  34.             HostApplicationServices.WorkingDatabase.LayerFilters = lft;
  35.  
  36.     }





edit:kdub :-> formatting code=csharp
« Last Edit: April 16, 2014, 01:58:33 PM by Kerry »

Chumplybum

  • Newt
  • Posts: 94
Re: XREF LAYER FILTER
« Reply #1 on: April 16, 2014, 08:27:50 PM »
I use this (vb.net) code to do the same thing:
Code - Visual Basic: [Select]
  1.     Public Overrides Sub Execute()
  2.  
  3.         Dim db As AADS.Database = AADS.HostApplicationServices.WorkingDatabase
  4.         Dim laytree As AALM.LayerFilterTree = db.LayerFilters
  5.  
  6.         If laytree.FilterExists(NONXREF_FILTER_NAME) = False Then
  7.             Dim newfilter As New AALM.LayerFilter
  8.             newfilter.Name = NONXREF_FILTER_NAME
  9.             newfilter.FilterExpression = "NAME==~*|*" '<--------------------------------------------
  10.  
  11.             ' Add the Layer Filter to the NestedFilters of the LayerFilters
  12.            laytree.Root.NestedFilters.Add(newfilter)
  13.             laytree.Root.GenerateNested()
  14.  
  15.             'Use the constructor to make the Layer Filter current
  16.            'and update the Layer Palette. Without this you can run the
  17.            'LAYER command and see the new layer filter
  18.            db.LayerFilters = New AALM.LayerFilterTree(laytree.Root, laytree.Root) '<--------------------------------------------
  19.        End If
  20.  
  21.     End Sub
  22.  

the only differences i found are highlighted with an arrow, at a guess i would think it has to do with this line in your code:
lfXref.FilterExpression = "NAME!=\"*|*\"";

i think it should be:
lfXref.FilterExpression = "NAME==""~*|*""";

or:
lfXref.FilterExpression = "NAME==\"~*|*\"";


cheers, Mark
« Last Edit: April 17, 2014, 12:12:24 AM by Chumplybum »

Bryco

  • Water Moccasin
  • Posts: 1851
Re: XREF LAYER FILTER
« Reply #2 on: April 17, 2014, 09:07:11 PM »
Thanks for the reply.
~ is a weirdo operator in c# so I can't use it at all.
No matter what I try so far , no go.
It's weird that it makes a filter w/ the correct name and makes it current
but doesn't do the same as a manual one.


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XREF LAYER FILTER
« Reply #3 on: April 17, 2014, 10:05:39 PM »

Bryce,
Can't test ..
How about using a literal string ?

@"NAME==~*|*"
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Bryco

  • Water Moccasin
  • Posts: 1851
Re: XREF LAYER FILTER
« Reply #4 on: April 18, 2014, 11:35:48 AM »
Nope didn't work either Kerry,  eInvalidInput

Well it looks like I needed that 2nd =
lfXref.FilterExpression = "NAME==\"~*|*\""; (I thought I had started with that duh)
Thanks guys,  this filter has been bugging me for a while.
« Last Edit: April 18, 2014, 11:42:29 AM by Bryco »

RC

  • Guest
Re: XREF LAYER FILTER
« Reply #5 on: April 21, 2014, 09:53:36 PM »
Sorry, no programming help, I just add the NO_XREF filter in my prototype and its always there.

Bryco

  • Water Moccasin
  • Posts: 1851
Re: XREF LAYER FILTER
« Reply #6 on: April 23, 2014, 01:00:37 AM »
long time no see and good point

Dave M

  • Newt
  • Posts: 187
Re: XREF LAYER FILTER
« Reply #7 on: April 23, 2014, 11:11:27 AM »
I use a free layer filter importer/exporter from DotSoft.  Here is a link: http://www.dotsoft.com/freestuff.htm
Cheers
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox