Parameter value filter skip empty parameter

Parameter value filter skip empty parameter

longt61
Advocate Advocate
1,656 Views
7 Replies
Message 1 of 8

Parameter value filter skip empty parameter

longt61
Advocate
Advocate

I am working on a app that allows user to read and modify schedule cell in Revit 2019. I tried to filter all elements in schedule view by the displayed field (parameter) for each row. The problem is that the ElementParameterFilter does not seem to work with empty cell (which mean the parameter does not have a value). 

I have been scratching my head for a while now, trying to parse the default value from empty cell as input, create a class inheriting ParameterValueProvider to override the value extracting behavior for the filtering process, but I get the same result. 

Ihaved attached 2 files for reproducible case: one for the code and one for revit project.

In the attached revit project file, I try to filter the wall whose Project parameter "test_weight" 's value is empty. You can take a look at the first element in the Schedule "Wall Schedule". You can modify the code for testing other case, of course.  Can anyone suggest a solution or a walkaround this problem?

0 Likes
Accepted solutions (1)
1,657 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni

The ElementParameterFilter has some interesting quirks.

  

You may find this discussion illuminating:

 

https://thebuildingcoder.typepad.com/blog/2021/01/parameter-filter-checking-element-type-and-ocr.htm...

  

https://forums.autodesk.com/t5/revit-api-forum/string-parameter-filtering-is-retrieving-false-data/t...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 8

RPTHOMAS108
Mentor
Mentor
Accepted solution

The parameter in question is double with units of kN. 

 

That kind of parameter would be blank in schedule for two main reasons:

1) Has never been given a value, use Parameter.HasValue or below

2) Row represents multiple elements with dissimilar parameter value

 

You may have found a good reason to use Parameter.HasValue but could also use:

ParameterValuePresenceRule

ParameterFilterRuleFactory.CreateHasNoValueParameterRule

ParameterFilterRuleFactory.CreateHasValueParameterRule
 
Have to also be careful with precision on double; the comparison is done with internal units i.e. the precision has to be related to a significant digit in display units converted to internal units (you may also need an extra decimal place for midpoint rounding). That's partly why I find it better to match via less than and greater than combinations rather than equals.
0 Likes
Message 4 of 8

mhannonQ65N2
Collaborator
Collaborator

When you use new in your method definition, you are hiding--not overriding--the base class's method. That means that anything that refers to your class via its specific type (NumericalFilterableValueProvider) will call your method, whereas anything that refers to it via its base type will call the base type method.

 

NumericalFilterableValueProvider foo = new NumericalFilterableValueProvider(document, parameterId);
double x = foo.GetDoubleValue(myElement); // Calls your GetDoubleValue method.

ParameterValueProvider bar = new NumericalFilterableValueProvider(document, parameterId);
double y = bar.GetDoubleValue(myElement); // Calls ParameterValueProvider's GetDoubleValue method.

 

 

Since the RevitAPI doesn't reference your NumericalFilterableValueProvider class, it will always call the method defined in ParameterValueProvider and never call your method.

0 Likes
Message 5 of 8

longt61
Advocate
Advocate
Thanks for pointing out the mistake in my code. Yes, I am aware about hiding the base class 's method. and yes, that was my mistake when provide incorrect code for analyzing. I did a few test with the code before posting and did not notice the mistake; however the problem remains after the fix. Hope you can shed some light on this.
0 Likes
Message 6 of 8

longt61
Advocate
Advocate
Dear Jeremy,
It have never occurred to me that the ElementParameterFilter can filter instance and type alike, thanks to your recommendation about making the most out of Revit filter, both quick and slow ones, before using .Net Linq. Now that is something I have to consider next time when I use ElementParameterFilter again. Though it does not solve my problem, it is much appriciated
0 Likes
Message 7 of 8

longt61
Advocate
Advocate

Dear Thomas,
The empty parameter value schedule cell is the direct result of my testing cases, and it is very common when users create many parameters (manually or using other addin) that they can not immediately fill in the required values, or it should be updated by other operations. And the empty schedule cell have been a real problem to me, and I am afraid that if the situation can not be improve I have to rework the whole command, which is nearly impossible since it had been reworked once due to the previous sloppy solution.


About your suggestions, Revit API 2019 does not support such methods. Even if it does, these methods only help me filtering out all element whose parameter values are empty/ not empty. The work after that has to be done manually, which is not very far away from rework the command since I can not make full use of ElementParameterFilter to filter elements whose empty parameter values can be interpreted with default value.


For example:
1. empty Double cell should be interpreted as 0
2. empty ElementId should be interpreted as ElementId.InvalidElementId (-1)


P/S: thanks for reminding me about the cell format (trailing unit symbol and precision), I believe I have solved the problem using the FormatOptions and convert display number into Internal value using UnitUtils.

0 Likes
Message 8 of 8

longt61
Advocate
Advocate
On a second thought, I can filter elements twice to achieve what I want. the first time for empty parameter elements (if any) and the second time for non-empty parameter elements. The result will be the intersection of 2 element sets.
Thank you very much for pointing me to the right direction.