GetFilteredNestedFamilyInstances() public static method

Returns a list of family instances found in the given family document whose family file name matches the given familyFileNameFilter and whose type name matches the given typeNameFilter. If no filter values are provided (or they evaluate to the empty string when trimmed) then all instances will be evaluated. Filtering is done with a simple Contains (substring) check, so wildcards don't work.
Because standard Revit filtering techniques fail when searching for nested families in a family document, we have no choice but to iterate over all elements in the family. While there usually aren't that many elements at the family level, nonetheless this method has been built for MAXIMUM SPEED.
public static GetFilteredNestedFamilyInstances ( string familyFileNameFilter, string typeNameFilter, Document familyDocument, bool caseSensitiveFiltering ) : List
familyFileNameFilter string The portion of the nested family file name (or exact match) to find
typeNameFilter string The portion of the type name (or exact match) to find
familyDocument Document The family document to search.
caseSensitiveFiltering bool Whether or not the filter checking is case-sensitive
return List
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            string familyFilenameFilter = string.Empty;
            string typeNameFilter       = string.Empty;
            bool   caseSensitive        = false;

            IEnumerable <Family> nestedFamilies
                = NestedFamilyFunctions.GetFilteredNestedFamilyDefinitions(
                      familyFilenameFilter, doc, caseSensitive);

            foreach (Family f in nestedFamilies)
            {
                Debug.WriteLine(f.Name);
            }

            List <FamilyInstance> instances
                = NestedFamilyFunctions.GetFilteredNestedFamilyInstances(
                      familyFilenameFilter, typeNameFilter, doc, caseSensitive);

            foreach (FamilyInstance fi in instances)
            {
                Debug.WriteLine(Util.ElementDescription(fi));
            }

            return(Result.Failed);
        }