TheSwamp

Code Red => .NET => Topic started by: T.Willey on August 11, 2006, 07:31:24 PM

Title: LayerFilterCollection, how do you use it?
Post by: T.Willey on August 11, 2006, 07:31:24 PM
I must be dumb!  I have been trying for an hour to use this, and nothing I do will get me anywhere.
Here is the code (doesn't work) that I've been trying.
Code: [Select]
using System;

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

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass (typeof(Test.LayerFilters))]

namespace Test
{
/// <summary>
/// Description of LayerFilters.
/// </summary>
public class LayerFilters {
[CommandMethod("PrintLayerFilters")]
public void PrintLayerFilters() {
Document ActDoc = AcadApp.DocumentManager.MdiActiveDocument;
Database DocDb = ActDoc.Database;
Editor DocEd = ActDoc.Editor;
using (Transaction DbTrans = (Transaction) DocDb.TransactionManager.StartTransaction()) {
LayerFilterCollection LayFilCol = (LayerFilterCollection) Autodesk.AutoCAD.LayerManager.LayerFilterCollection;
foreach (LayerFilter LayFil in LayFilCol) {
DocEd.WriteMessage ("\n Name: {0}", LayFil.Name);
}
}
}
}
}
Here is the error message that most often comes up.
Quote from:  Error message
'Autodesk.AutoCAD.LayerManager.LayerFilterCollection' denotes a 'class' where a 'variable' was expected.

Any/all help is appreciated.
Title: Re: LayerFilterCollection, how do you use it?
Post by: Kerry on August 12, 2006, 06:50:58 PM
Hi Tim,
Perhaps something like this ..
Code: [Select]
//
// kwb@theswamp 20060813
// PrintLayerFilters
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.EditorInput;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

 [assembly: CommandClass(typeof(kdubTest.LayerFilters))]

namespace kdubTest
{
    /// <summary>
    /// List of LayerFilters Names.
    /// </summary>
    public class LayerFilters
    {
        [CommandMethod("Test2")]
        public void PrintLayerFilters2()
        {
            Editor ed
                = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            LayerFilterCollection layerFilterCollection
                = HostApplicationServices.WorkingDatabase.LayerFilters.Root.NestedFilters;
            foreach (LayerFilter layerFilter in layerFilterCollection)
            {
                ed.WriteMessage("\n Name: {0}", layerFilter.Name );
            }
        }
    }
}

edit:  cleaned up .. as usually happens with testing, some extraneous rubbish creeps in
Title: Re: LayerFilterCollection, how do you use it?
Post by: MickD on August 12, 2006, 09:31:44 PM
Nice optimisation Kerry :)
I had a bit of a go at it yesterday and was thinking the 'tree was the answer, but you made it even better in that version, nice work.
Title: Re: LayerFilterCollection, how do you use it?
Post by: Kerry on August 13, 2006, 02:22:35 AM
Yes Mick, the second version is a little cleaner .. :-)

I'm looking forward to being able to play with this stuff more often than just on Sundays ... it's a shame when real work gets in the way .
Title: Re: LayerFilterCollection, how do you use it?
Post by: T.Willey on August 13, 2006, 05:21:11 PM
Thanks Kerry.  I will have a look at this one Monday at work.  But it still looks like you can't get the default filters, is that true?
Title: Re: LayerFilterCollection, how do you use it?
Post by: Kerry on August 13, 2006, 05:24:17 PM
Tim, What are the default filters ?
Title: Re: LayerFilterCollection, how do you use it?
Post by: T.Willey on August 14, 2006, 11:11:45 AM
Mainly it is the xref one.  I was thinking it would be nice, since it can't be done in lisp, is to be able to set the layer filters to all xrefs, and then hit the toggle button so that it is reversed, so xref layers won't show, and then hit the toggle so that it show in the drop down list the same.  I will see if I can get this to work today with your code, as I see that in the test drawing you had it had no xrefs, so maybe the same method will work.  I only have a half day today, and then I will be out the rest of the week.

Thanks Kerry.

Edit:  Looks like it will grab the xref (default once an xref is inserted).  If one wanted to dig down more, then one would have to write more code, as it stops at the top level, but this is the starting point I was looking for.  Thanks again Kerry.  Will post what I find.


Edit2:  I don't see a way to do this. :(