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);
}
Solved! Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
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:
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 🙂
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.
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 ?
Can't find what you're looking for? Ask the community or share your knowledge.