Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filter according to shared parameter

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
lrsmns
245 Views, 5 Replies

Filter according to shared parameter

Hi,

 

I'm trying to collect family symbols that contain a specific value from a shared parameter...
Typically I would collect them according to a specific BuiltInCategory, but since there are multiple categories within the collection, I would first get the Elements, use the LookupParameter method, and cast it to FamilySymbols; but now with this approach its not working. 

 

Would appreciate any insights! Thank you! 

 

 

public ObservableCollection<RevitFamilyWrapper> CollectObjects(string ParameterValue)
{
    

    var familySymbols = new FilteredElementCollector(doc)
            .OfClass(typeof(Element))
            .Where(x => x.LookupParameter("ParameterName").HasValue &&
            x.LookupParameter("ParameterName").AsString().Equals(ParameterValue))
            .Cast<FamilySymbol>()
            .Select(x => new RevitFamilyWrapper(x));
   

    return new ObservableCollection<RevitFamilyWrapper>(familySymbols);
}

 

 

5 REPLIES 5
Message 2 of 6
jeremy_tammik
in reply to: lrsmns

You can filter for several categories at the same time by combining several category filters with a logical OR filter:

  

  

The most efficient way to filter for specific parameter values is to use a parameter filter:

  

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 3 of 6
Mohamed_Arshad
in reply to: lrsmns

HI @lrsmns 
    FamilySymbol is the base class for all family Categories. So you can apply for multiple category, and don't need to filter using Element, we can directly use the FamilySymbol in our filter. Kindly check the below updated code.

 

Reference Code

 

 

 public ObservableCollection<RevitFamilyWrapper> CollectObjects(string ParameterValue, Document doc)
        {
            var familySymbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol))
                .Where(x => x.LookupParameter("ParameterName").HasValue &&
                x.LookupParameter("ParameterName").AsString().Equals(ParameterValue))
                .Select(x => new RevitFamilyWrapper(x as FamilySymbol));

            return new ObservableCollection<RevitFamilyWrapper>(familySymbol);
        }

 

 

 

Hope this will Helps 🙂

Thanks & Regards,
Mohamed Arshad K
Message 4 of 6
lrsmns
in reply to: Mohamed_Arshad

I have tried that approach, however it returned null within the LookupParameter method...

 

I assumed that since LookupParameter method lies under the Element class method, it needs to collect as Element type first. However, as i showed in the code above, it still doesnt work.

 

 

Message 5 of 6
Mohamed_Arshad
in reply to: lrsmns

HI @lrsmns 
    Null is returned because a few family symbols do not has the parameter loaded. So it is returned null. You can add the condition to check the null as well.

 

    The lookup Parameter method will work for all Class because it from the base Class Element. So we don't need to worry about that

 

 

 public ObservableCollection<RevitFamilyWrapper> CollectObjects(string ParameterValue, Document doc)
        {
            var familySymbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol))
                .Where(x =>
                x.LookupParameter("ParameterName") != null &&  //NUll Checking
                x.LookupParameter("ParameterName").HasValue && //Empty Checking
                x.LookupParameter("ParameterName").AsString().Equals(ParameterValue)) //Exact Value Checking
                .Select(x => new RevitFamilyWrapper(x as FamilySymbol));

            return new ObservableCollection<RevitFamilyWrapper>(familySymbol);
        }

 

 

Have you tried above method ?

 

Thanks & Regards,
Mohamed Arshad K
Message 6 of 6
lrsmns
in reply to: Mohamed_Arshad

Ahaa got it! Thank you so much for the helfpul hint

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community