Get all elements in a project that have a parameter with a value.

Get all elements in a project that have a parameter with a value.

Anonymous
Not applicable
3,375 Views
5 Replies
Message 1 of 6

Get all elements in a project that have a parameter with a value.

Anonymous
Not applicable

I have this code.

 

ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(5539));
FilterStringRuleEvaluator fsre = new FilterStringEquals();

 

FilterRule fRule = new SharedParameterApplicableRule("sharedparameter");
ElementParameterFilter filter = new ElementParameterFilter(fRule);


FilterRule fRule2 = new FilterStringRule(pvp, fsre,"",false);
ElementParameterFilter filter2 = new ElementParameterFilter(fRule2);

 

FilteredElementCollector col = new FilteredElementCollector(doc).WhereElementIsNotElementType().WherePasses(filter).WherePasses(filter2);

 

This code selects all elements in the project that have the specified shared parameter and where the value is "". But I'm looking for the inverse of this. Getting all elements that have the shared parameter and has some value. Is there some way to inverse the FilterStringRule?

0 Likes
Accepted solutions (1)
3,376 Views
5 Replies
Replies (5)
Message 2 of 6

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

ElementParameterFilter has a constructor with a boolean parameter for inversion.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 6

matthew_taylor
Advisor
Advisor

Hi @Anonymous,

A lot of the filters have overloads that allow the filter to be 'inverted'. That's a good place to start.

 

To be honest, I think you'll need to approach your issue in a slightly different way. The filter you are trying to implement will return elements where the parameter has no value at all, that is, parameter.HasValue = false.

 

Cheers,

 

-Matt

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 4 of 6

Anonymous
Not applicable

 

Yeah you are completely right I was looking for something like that but completely missed in the documentation

0 Likes
Message 5 of 6

juancalvoferrandiz
Enthusiast
Enthusiast

Hello,

Very interesting theme.

 

I'm trying to do something similiar but with no result:

 

I understand that with your code you must know the ID of the parameter ("5539").

 

I'm trying to do with the name and value 1/0 (yes / no parameter).

 

I know how to do it with a BuiltInParameter but no how to do it with a shared parameter:

 

// Built in Parameter

            BuiltInParameter testParam = BuiltInParameter.FUNCTION_PARAM;
            ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)testParam));
            FilterNumericEquals fnrv = new FilterNumericEquals();
            FilterIntegerRule paramFr = new FilterIntegerRule(pvp, fnrv, ruleValInt);
            ElementParameterFilter epf = new ElementParameterFilter( paramFr );

            FilteredElementCollector doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WherePasses(epf); ;
            doors.OfClass(typeof(FamilyInstance));

// Shared Parameter ??

Parameter parameter = data.GetParameters(LabConstants.SharedParamsDefFireRating);
                    
            ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)parameter));
            FilterNumericEquals fnrv = new FilterNumericEquals();
            FilterIntegerRule paramFr = new FilterIntegerRule(pvp, fnrv, ruleValInt);
            ElementParameterFilter epf = new ElementParameterFilter( paramFr );

            FilteredElementCollector doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WherePasses(epf); ;
            doors.OfClass(typeof(FamilyInstance));

Any help is wellcome. Thanks. 

 

Good afternoon.

0 Likes
Message 6 of 6

matthew_taylor
Advisor
Advisor

Hi @juancalvoferrandiz,

You are best starting a new topic.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes