Author Topic: LayerFilterCollection, how do you use it?  (Read 3444 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
LayerFilterCollection, how do you use it?
« 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: LayerFilterCollection, how do you use it?
« Reply #1 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
« Last Edit: August 12, 2006, 06:57:59 PM by Kerry Brown »
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.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: LayerFilterCollection, how do you use it?
« Reply #2 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.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: LayerFilterCollection, how do you use it?
« Reply #3 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 .
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: LayerFilterCollection, how do you use it?
« Reply #4 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?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: LayerFilterCollection, how do you use it?
« Reply #5 on: August 13, 2006, 05:24:17 PM »
Tim, What are the default filters ?
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: LayerFilterCollection, how do you use it?
« Reply #6 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. :(
« Last Edit: August 14, 2006, 11:47:33 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.