.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting active Layerfilter

12 REPLIES 12
Reply
Message 1 of 13
Nikome
469 Views, 12 Replies

Setting active Layerfilter

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!
12 REPLIES 12
Message 2 of 13
Anonymous
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!
Message 3 of 13
Nikome
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...
Message 4 of 13
Anonymous
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...
Message 5 of 13
Nikome
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?
Message 6 of 13
Nikome
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...
Message 7 of 13
Anonymous
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?
Message 8 of 13
Nikome
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!
Message 9 of 13
Anonymous
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!
Message 10 of 13
Nikome
in reply to: Nikome

With not being a native I mean't english is not my native language 😉

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.
Message 11 of 13
caddie75
in reply to: Nikome

Hi Tony,

I've tried this also, I can create the Filters. But can't set any active/current.

The Root and Current Property of Autodesk.AutoCAD.LayerManager.LayerFilterTree is Read-Only.
(in the Managed API).

And Changing the name property of Current/Root will only change the name of that current Filter...

But I see that the New method of the Class can set the layerFilter as a object??
I've just quickly tried it and works:
lf1 = the new layerFilter you want active.
Dim newFilterTree As New LayerFilterTree(lft.Root, lf1)
db.LayerFilters = newFilterTree

Watch out for double filter names, the LayerFilterCollection doesn't thows a error.
And in the Layermanager you can see double names, if you try to delete one Autocad crashes.

AutoCAD 2009 / Vista Sp1

Greetz
Michel.
Message 12 of 13
caddie75
in reply to: Nikome

Hi,



Spoke to Soon, using the New method with the Root and a LayerFilter only works

if a layerfilter in the layermanager was selected first on a newly opened drawing.



Guess the Layerfilter needs to be initialized before a filter can be used???



Michel
Message 13 of 13
joantopo
in reply to: caddie75

I use:

   Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_+layer ", true, false, true);

 but this command doesn´t select very well... filter appears in gray color instead of blue color selection.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost