Inverse View Filter Rules

Inverse View Filter Rules

Anonymous
Not applicable
1,491 Views
4 Replies
Message 1 of 5

Inverse View Filter Rules

Anonymous
Not applicable

Hi All,

I am trying to make an addin (Revit 2018 with C#) that lists all the view filter in a project, with their name, their category(ies), filter rules and filter values.

As long as there are no inverse filter rules it works.

Please see this example:

if (rule is FilterDoubleRule)
{
FilterDoubleRule fdr = rule as FilterDoubleRule;

if (fdr.GetEvaluator().GetType().Equals(typeof(FilterNumericLess)))
comparator = "<";
else if (fdr.GetEvaluator().GetType().Equals(typeof(FilterNumericEquals)))
comparator = "=";

else if (fdr.GetEvaluator().GetType().Equals(typeof(FilterNumericLessOrEqual)))
comparator = "<=";

else if (fdr.GetEvaluator().GetType().Equals(typeof(FilterNumericGreater)))
comparator = ">";

else if (fdr.GetEvaluator().GetType().Equals(typeof(FilterNumericGreaterOrEqual)))
comparator = ">=";

ruleValue = fdr.RuleValue.ToString();

}

I do the same for the Integer and String rules. And this works.

But when there are inverse filter rules like "Not Equal", "Does Not Contain", "Does not Begin with", ... then I don't know how to access the filter rule and rule value.

I hope that somebody here can help me.

Thank you in advance.

0 Likes
Accepted solutions (1)
1,492 Views
4 Replies
Replies (4)
Message 2 of 5

CADsoftOrl
Contributor
Contributor

Negated filters are wrapped in a FilterInverseRule object, so you'll need to check if your FilterRule is a FilterInverseRule, and if so, call FilterInverseRule.GetInnerRule().

 

if (rule is FilterInverseRule inverseRule)
{
    FilterRule innerRule = inverseRule.GetInnerRule();
    if (innerRule is FilterDoubleRule fdr)
    {
        ...

    }
}

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for your answer.

I still have a question.

Let's say the innerRule is filterStringRule, that means the rule could be: "is not equal", Does not begin with", Does not end with" and "does not contain".

How can I figure out which one of these rules is used in the filter?

Thank you.

0 Likes
Message 4 of 5

CADsoftOrl
Contributor
Contributor
Accepted solution

You would want to look at the type returned by FilterStringRule.GetEvaluator().

 

if (rule is FilterStringRule fsr)
{
    FilterStringRuleEvaluator evaluator = fsr.GetEvaluator();
    if (evaluator is FilterStringBeginsWith)
    {
        // If the outer-most rule was a FilterInverseRule, 
        // and FilterInverseRule.GetInnerRule() returned a FilterStringRule
        // with a FilterStringBeginsWith evaluator, 
        // then this is a "Does not begin with" rule
    }
    else if (evaluator is FilterStringContains)
    {
        ...
}
0 Likes
Message 5 of 5

Anonymous
Not applicable

Great. That works.

Thank you very much.

0 Likes