Apply a saved view filter?

Apply a saved view filter?

Anonymous
Not applicable
941 Views
10 Replies
Message 1 of 11

Apply a saved view filter?

Anonymous
Not applicable

Hi,

 

I've got a bunch of filter conditions (about 75) that I need to configure for a given view, with certain parameters. I'm thinking this should be fairly simple via the API. Basically the process is:

 

1. Add my pre-constructed view filters to the current view (Vis/Graph -> Filters -> Add)

2. Configure the visibility overrides for each filter (Filters - > Overrides)

3. Done

 

So, first question is: if I have a saved filter, say "Myfilter", how do I add it to the current view? I know it's via view.addfilter(), but I can't figure out how to get the ElementID parameter addfilter takes, for my filter based on its name. Or how to get a list (Ilist?) of the view filters available in the model, through which you could iterate and test for your desired name.

 

Second question, it would seem like an attractive option to simply create the filters I need from scratch. I've seen several examples in the SDK that cover creating view filters. Except that most of the examples simply filter on a built-in parameter (for example filter all the walls in the model). The parameter I need to filter on is a user-defined project parameter (not shared tho). How would you go about creating a filter based on one of these user-defined parameters?

 

0 Likes
942 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
I'd probably start with digging into this sample:
SDKs\Revit 2016\Samples\ElementFilter\ViewFilters

Most of what you're looking for is in there, including code to find all view filters.
Message 3 of 11

Anonymous
Not applicable
Ok, I've managed to start manipulating visibility and filter parameters. Unfortunately I can't figure out how to set a certain filter to a solid fill pattern.

I'm iterating through the list of filters in the current view and using:

mygraphicsoverride.SetCutFillPatternId(....);

But, I can't figure out what to apply at "..." to get it to use a solid fill pattern. Any ideas?
0 Likes
Message 4 of 11

Anonymous
Not applicable

+ Id {4} Autodesk.Revit.DB.ElementId

 

So I think 4 of {4} will do the trick ....

0 Likes
Message 5 of 11

Revitalizer
Advisor
Advisor

Hi,

 

you can use a FilteredElementCollector to get the FillPatternElement you need.

When iterating over the FillPatternElements, you can get the solid one by its FillPattern.IsSolidFill property.

(Its FillPattern can be got by FillPatternElement.GetFillPattern()).

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 6 of 11

Anonymous
Not applicable

Dim TestCollector As New FilteredElementCollector(m_uidoc.Document)
Dim TestIterator As FilteredElementIterator = TestCollector.OfClass(GetType(FillPatternElement)).GetElementIterator
TestIterator.Reset()

For Each fp As FillPatternElement In TestCollector

Next

 

In my case the solid fill returned integer = 4

0 Likes
Message 7 of 11

Revitalizer
Advisor
Advisor

Hi,

 

An ElementId can vary between different documents, so your value of "4" will probably not work for him.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 8 of 11

Anonymous
Not applicable

Absolutely true. I realised that also and therefore I provided a little code. You can find the ElementId by looking for a FillPatern named 'Solid fill'. 

 

Dim TestCollector As New FilteredElementCollector(m_uidoc.Document)
Dim TestIterator As FilteredElementIterator = TestCollector.OfClass(GetType(FillPatternElement)).GetElementIterator
TestIterator.Reset()

For Each fp As FillPatternElement In TestCollector
If fp.Name.ToString = "Solid fill" Then
Dim elementId As ElementId = fp.Id
Exit For
End If
Next

Message 9 of 11

Revitalizer
Advisor
Advisor

Hi,

 

no need to get an Element by comparison of names.

As I've written above, there is an IsSolidFill property which allows to get it language-independent.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 10 of 11

Anonymous
Not applicable
Didn't realise that. And it works fine too. Now I have to remember that for the next time I need it 😉
0 Likes
Message 11 of 11

Anonymous
Not applicable

What's with all the FilterElementCollectors in the Revit API? Seems everything revolves around a collector and a whole bunch of type conversions and obscure class members. I'm surprised commenting out code doesn't require a collector!

 

Couldn't Autodesk just have defined a built in constant called "FILLPATTERN_SOLID" or something? Would have turned out a whole lot easier.