Programatically create new graphic override filter

Programatically create new graphic override filter

Anonymous
Not applicable
2,241 Views
3 Replies
Message 1 of 4

Programatically create new graphic override filter

Anonymous
Not applicable

Im trying to programatically create a new graphic override filter that would simulate the following:

 

original.png

 

i have pieced this together but it isnt working.

 

Private Sub CreateViewFilter(ByVal doc As Autodesk.Revit.DB.Document, ByVal view As Autodesk.Revit.DB.View, objColor As Autodesk.Revit.DB.Color)
  Using trans As New Transaction(doc, "create filter override")
    trans.Start()

    Dim cats As IList(Of ElementId) = New List(Of ElementId)
    cats.Add(New ElementId(BuiltInCategory.OST_Rebar))    
    Dim parameterFilterElement As ParameterFilterElement = parameterFilterElement.Create(doc, "RelNo=001", cats)

    Dim parameterCollector As FilteredElementCollector = New FilteredElementCollector(doc)
    'Dim parameter As Parameter = ParameterCollector.OfClass(System.Type.GetType(Autodesk.Revit.DB.Rebar)).FirstElement().get_Parameter("RelNo")
    Dim parameter As Parameter = parameterCollector.OfType(Of Rebar).First.GetParameters("RelNo")

    Dim filterRules As IList(Of FilterRule) = New List(Of FilterRule)
    filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, "001", True))
    parameterFilterElement.SetRules(filterRules)

    Dim filterSettings As OverrideGraphicSettings = New OverrideGraphicSettings()
    filterSettings.SetProjectionFillColor(objColor)
    view.AddFilter(parameterFilterElement.Id)
    view.SetFilterOverrides(parameterFilterElement.Id, filterSettings)
    trans.Commit()
  End Using

End Sub

 

 

Once i have created the filter and graphical overide, i assume that the code would be similar to read back color and name from the revit...is that true?

 

Any assistance is appreciated.

Kevin

 

0 Likes
2,242 Views
3 Replies
Replies (3)
Message 2 of 4

Revitalizer
Advisor
Advisor

Hi,

is your parameter a type parameter ?

Have you tried to remove this:
parameterFilterElement.SetRules(filterRules)

and tried to add the rules directly in the ParameterFilterElement.Create method:
Dim parameterFilterElement As ParameterFilterElement = parameterFilterElement.Create(doc, "RelNo=001", cats, filterRules)
?

I know that this should not make a difference, but since it is the Revit API, you never know...

A third point: before creating a ParameterFilterElement of that name, have you checked if there is already an existing one of that name ?
Don't know if Revit will throw an exception if not.


Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 4

Anonymous
Not applicable

Thanks Revitalizer!!!

 

I finally got it to work with the following code:

 

 

 

        Try
            Using trans As New Transaction(doc, "CreateFilterOverride")
                trans.Start()
                Dim cats As IList(Of ElementId) = New List(Of ElementId)
                cats.Add(New ElementId(BuiltInCategory.OST_Rebar))

                Dim parameterCollector As FilteredElementCollector = New FilteredElementCollector(doc, view.Id)

                Dim parameter As Parameter = parameterCollector.OfClass(GetType(Rebar)).FirstElement().LookupParameter("RelNo")

                Dim filterRules As IList(Of FilterRule) = New List(Of FilterRule)
                filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, strRel, False))

                Dim parameterFilterElement As ParameterFilterElement = parameterFilterElement.Create(doc, strRel, cats, filterRules)

                Dim filterSettings As OverrideGraphicSettings = New OverrideGraphicSettings()
                filterSettings.SetProjectionFillColor(objColor)
                filterSettings.SetProjectionFillPatternId(PatId)

                view.AddFilter(parameterFilterElement.Id)
                view.SetFilterOverrides(parameterFilterElement.Id, filterSettings)

                trans.Commit()
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

now im not sure how to set the fillpattern to solid fill, i think i need to use :

 

     filterSettings.SetProjectionFillPatternId(PatId)

but how do i get the PatID

 

 

how can i check to see if filters exist?  i started looking at the view.getfilters and i see that it is adding new filters by .count, but i havent found how to check its name, color, etc..

 

 

Thanks again for you help

 

Kevin

 

 

0 Likes
Message 4 of 4

Revitalizer
Advisor
Advisor

Hi,

 

you can get both the FillPatternElement and ParameterFilterElement using a FilteredElementCollector, as with nearly every Element derived class.

RevitAPI.chm says:

 

"There is a small subset of Element subclasses in the API that are not supported by this filter. These classes exist in the API, but not in Revit's native object model, which means that this filter doesn't support them. In order to use a class filter to find elements of these types, it is necessary to use a higher level class and then process the results further to find elements matching only the subclass. For a list of subclasses affected by this restriction, consult the documentation for ElementClassFilter."

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes