SetFilterOverrides Method


Sets the overrides associated with a filter.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2014

Syntax

C#
public void SetFilterOverrides(
	ElementId filterElementId,
	OverrideGraphicSettings overrideGraphicSettings
)
Visual Basic
Public Sub SetFilterOverrides ( _
	filterElementId As ElementId, _
	overrideGraphicSettings As OverrideGraphicSettings _
)
Visual C++
public:
void SetFilterOverrides(
	ElementId^ filterElementId, 
	OverrideGraphicSettings^ overrideGraphicSettings
)

Parameters

filterElementId
Type: Autodesk.Revit.DBElementId
ElementId of the filter.
overrideGraphicSettings
Type: Autodesk.Revit.DBOverrideGraphicSettings
The overrides to apply to the filter.

Remarks

If the filter is not currently applied to the view, this will add the filter with the assigned overrides.

Examples

CopyC#
public static void ModifyExistingFilter(Document doc, View view)
{
    // Find any filter with overrides setting cut color to Red
    Dictionary<ElementId, OverrideGraphicSettings> filterIdsToChange = new Dictionary<ElementId, OverrideGraphicSettings>();

    foreach (ElementId filterId in view.GetFilters())
    {
        OverrideGraphicSettings overrideSettings = view.GetFilterOverrides(filterId);

        Color lineColor = overrideSettings.CutLineColor;

        if (lineColor == Color.InvalidColorValue)
            continue;

        // Save overrides setting the cut color to green
        if (lineColor.Red == 0xFF && lineColor.Green == 0x00 && lineColor.Blue == 0x00)
        {
            overrideSettings.SetCutLineColor(new Color(0x00, 0xFF, 0x00));
            filterIdsToChange[filterId] = overrideSettings;
        }
    }

    // Make the change to all found filters
    using (Transaction t = new Transaction(doc, "Change override filters"))
    {
        t.Start();

        foreach (ElementId filterId in filterIdsToChange.Keys)
        {
            view.SetFilterOverrides(filterId, filterIdsToChange[filterId]);
        }
        t.Commit();
    }
}
CopyVB.NET
Public Shared Sub ModifyExistingFilter(doc As Document, view As View)
    ' Find any filter with overrides setting cut color to Red
    Dim filterIdsToChange As New Dictionary(Of ElementId, OverrideGraphicSettings)()

    For Each filterId As ElementId In view.GetFilters()
        Dim overrideSettings As OverrideGraphicSettings = view.GetFilterOverrides(filterId)

        Dim lineColor As Color = overrideSettings.CutLineColor

        If lineColor.IsValid = False Then
            Continue For
        End If

        ' Save overrides setting the cut color to green
        If lineColor.Red = &Hff AndAlso lineColor.Green = &H0 AndAlso lineColor.Blue = &H0 Then
            overrideSettings.SetCutLineColor(New Color(&H0, &Hff, &H0))
            filterIdsToChange(filterId) = overrideSettings
        End If
    Next

    ' Make the change to all found filters
    Using t As New Transaction(doc, "Change override filters")
        t.Start()

        For Each filterId As ElementId In filterIdsToChange.Keys
            view.SetFilterOverrides(filterId, filterIdsToChange(filterId))
        Next
        t.Commit()
    End Using
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException ElementId is not associated with a FilterElement. -or- Fill pattern must be a drafting pattern. -or- Fill pattern Id must be invalidElementId or point to a LinePattern element.
Autodesk.Revit.ExceptionsArgumentNullException A non-optional argument was null
Autodesk.Revit.ExceptionsInvalidOperationException The element "this View" does not belong to a project document. -or- The view type does not support Visibility/Graphics Overriddes.

See Also