.NET

Reply
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 1 of 13 (212 Views)

Setting active Layerfilter

212 Views, 12 Replies
03-23-2009 10:06 AM
Greetings!

I'm trying to set the active Layerfilter. I tried myDB.LayerFilters.Root.Name = "Filter1" but it wouldn't work. Couldn't find help neither here nor on Kean's Blog, so anyone got an idea about this?

Thanks for trying!
*Tony Tanzillo
Message 2 of 13 (212 Views)

Re: Setting active Layerfilter

03-23-2009 01:01 PM in reply to: Nikome
After that, do this:

myDB.LayerFilters = myDB.LayerFilters

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6147056@discussion.autodesk.com...
Greetings! I'm trying to set the active Layerfilter. I tried
myDB.LayerFilters.Root.Name = "Filter1" but it wouldn't work. Couldn't find
help neither here nor on Kean's Blog, so anyone got an idea about this?
Thanks for trying!
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 3 of 13 (212 Views)

Re: Setting active Layerfilter

03-23-2009 11:50 PM in reply to: Nikome
Not sure if we understand each other correctly. I want to set the ACTIVE or CURRENT Layerfilter of a new drawingdatabase. So once I open the drawing, this Layerfilter is active and filters out all unwanted layers.

Also myDB.LayerFilters.Root.Name = "Filter1" is not wokring because it wouldn't do anything, but it is not working because it says: eNotApplicable.

Basically I understand you relate upon the fact, that the LayerFilters need to be casted, changed and casted back again.That's what I read on Keans blog, and I used some of his code as well to create this:

Public Function mkLayerFilter(ByVal myDB As Database, ByVal filterName As String, ByVal filterData As String) As Boolean
Try
' Read Layerfilters
Dim lft As LayerFilterTree = myDB.LayerFilters
Dim lfc As LayerFilterCollection = lft.Root.NestedFilters
' Add Layerfilter
Dim lf1 As New LayerFilter()
lf1.Name = filterName
lf1.FilterExpression = filterData
lfc.Add(lf1)
' Write Layerfilters
'lft.Root.Name = filterName 'eNotApplicable
myDB.LayerFilters = lft

'myDB.LayerFilters.Root.Name = filterName 'eNotApplicable
'myDB.LayerFilters = myDB.LayerFilters

Catch ex As Exception
MsgBox("Exception: {0}", ex.Message)
End Try
End Function

But neither nor is working...
*Tony Tanzillo
Message 4 of 13 (212 Views)

Re: Setting active Layerfilter

03-24-2009 01:33 PM in reply to: Nikome
If it's a new database created from scratch, then I suspect
that it doesn't have the 'default' filters that AutoCAD adds
(e.g., "All Layers", "All Used Layers"), and that's the problem.

Those are special layer filters, and I've never tried adding
them to a new database.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6147508@discussion.autodesk.com...
Not sure if we understand each other correctly. I want to set the ACTIVE or
CURRENT Layerfilter of a new drawingdatabase. So once I open the drawing,
this Layerfilter is active and filters out all unwanted layers. Also
myDB.LayerFilters.Root.Name = "Filter1" is not wokring because it wouldn't
do anything, but it is not working because it says: eNotApplicable.
Basically I understand you relate upon the fact, that the LayerFilters need
to be casted, changed and casted back again.That's what I read on Keans
blog, and I used some of his code as well to create this: Public Function
mkLayerFilter(ByVal myDB As Database, ByVal filterName As String, ByVal
filterData As String) As Boolean Try ' Read Layerfilters Dim lft As
LayerFilterTree = myDB.LayerFilters Dim lfc As LayerFilterCollection =
lft.Root.NestedFilters ' Add Layerfilter Dim lf1 As New LayerFilter()
lf1.Name = filterName lf1.FilterExpression = filterData lfc.Add(lf1) ' Write
Layerfilters 'lft.Root.Name = filterName 'eNotApplicable myDB.LayerFilters =
lft 'myDB.LayerFilters.Root.Name = filterName 'eNotApplicable
'myDB.LayerFilters = myDB.LayerFilters Catch ex As Exception
MsgBox("Exception: {0}", ex.Message) End Try End Function But neither nor is
working...
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 5 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 02:20 AM in reply to: Nikome
Ok so I tried it with an existing file instead, but the error message stays the same. eNotApplicable when it comes to setting lft.Root.Name

Are you really sure that there is nothing wrong with how I am doing this?
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 6 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 02:26 AM in reply to: Nikome
hmm I had some doubts about my plans. Started a new drawing, addad a layerfilter, made it active, saved, reopened the drawing and recognized, that the layerfilter was no longer set active.
So I guess that means, there can't be such a thing as an active Layerfilter, at least not for a Database. Made me sad...
*Tony Tanzillo
Message 7 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 07:05 AM in reply to: Nikome
You can't set the root layer filter. You can only add child filters to it,
and
yes, you can make them active (which is the what the second argument
is for).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6148461@discussion.autodesk.com...
Ok so I tried it with an existing file instead, but the error message stays
the same. eNotApplicable when it comes to setting lft.Root.Name Are you
really sure that there is nothing wrong with how I am doing this?
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 8 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 08:11 AM in reply to: Nikome
Sorry I'm no native, so maybe it's my lack of english that prevents me from understanding what secound argument you are reffering to, but I really don't get it.


Dim lft As LayerFilterTree = myDB.LayerFilters
Dim lfc As LayerFilterCollection = lft.Root.NestedFilters

Dim lf1 As New LayerFilter()
lf1.Name = filterName
lf1.FilterExpression = filterData
lfc.Add(lf1)
myDB.LayerFilters = lft

Where in that code would I need to make what change so that the newly created layerfilter "lf1" is set to be active?

Thanks for helping!
*Tony Tanzillo
Message 9 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 08:52 AM in reply to: Nikome
Sorry, I'm thinking the native API, not the managed API.

The Current property of the LayerFilterTree sets the current layer filter,
and it must be set before you reassign the object to the Database's
LayerFilters property.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6148749@discussion.autodesk.com...
Sorry I'm no native, so maybe it's my lack of english that prevents me from
understanding what secound argument you are reffering to, but I really don't
get it. Dim lft As LayerFilterTree = myDB.LayerFilters Dim lfc As
LayerFilterCollection = lft.Root.NestedFilters Dim lf1 As New LayerFilter()
lf1.Name = filterName lf1.FilterExpression = filterData lfc.Add(lf1)
myDB.LayerFilters = lft Where in that code would I need to make what change
so that the newly created layerfilter "lf1" is set to be active? Thanks for
helping!
Active Contributor
Nikome
Posts: 36
Registered: ‎02-13-2008
Message 10 of 13 (212 Views)

Re: Setting active Layerfilter

03-25-2009 09:55 AM in reply to: Nikome
With not being a native I mean't english is not my native language :smileywink:

But I think I got now, what you were trying to tell me.

Instead of:

Dim lfc As LayerFilterCollection = lft.Root.NestedFilters

I should use:

Dim lfc As LayerFilterCollection = lft.Current.NestedFilters


Problem is, when I do that I get an unhandeled AutoCAD Error and Programm crashes imediatly. I think this could have been, what you were refering to, when you said something about the new Database not having any standard Filters. So maybe I just need to try this with a non empty database, which is, if no other comments are being made, what I will try tomorrow.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.