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.
[CommandMethod("NoXrefLayers")]
static public void NoXrefLayers()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
bool bXref = false;
LayerFilterTree lft = db.LayerFilters;
LayerFilterCollection lfc = db.LayerFilters.Root.NestedFilters;
for (int i = 0; i < lfc.Count; ++i)
{
LayerFilter lf = lfc[i];
ed.WriteMessage(Environment.NewLine + lf.FilterExpression);
if (lf.Name == "Xref") //only shows up if there is an xref
bXref = true;
else if(lf.Name=="no_xref_layers")
{
LayerFilterTree lyrTree2
= new LayerFilterTree
(lft
.Root, lf
); HostApplicationServices.WorkingDatabase.LayerFilters = lyrTree2;
return;
}
}
if (!bXref) return;
LayerFilter lfXref
= new LayerFilter
(); lfXref
= new LayerFilter
(); lfXref.Name = "no_xref_layers";
lfXref.FilterExpression = "NAME!=\"*|*\"";
lft.Root.NestedFilters.Add(lfXref);
lft
= new LayerFilterTree
(lft
.Root, lfXref
); HostApplicationServices.WorkingDatabase.LayerFilters = lft;
}
edit:kdub :-> formatting code=csharp