BuildingCoder.NestedFamilyFunctions.GetFilteredNestedFamilyDefinitions C# (CSharp) Метод

GetFilteredNestedFamilyDefinitions() публичный статический Метод

Returns a list of the nested family files in the given family document whose name matches the given family file name filter. Useful for checking to see if a family desired for nesting into the host family document is already nested in. 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 speed.
public static GetFilteredNestedFamilyDefinitions ( string familyFileNameFilter, Document familyDocument, bool caseSensitiveFiltering ) : IEnumerable
familyFileNameFilter string The portion of the family file loaded into the family document
familyDocument Document The family document being queried
caseSensitiveFiltering bool Whether or not the filter checking is case-sensitive
Результат IEnumerable
        public static IEnumerable<Family> GetFilteredNestedFamilyDefinitions(
            string familyFileNameFilter,
            Document familyDocument,
            bool caseSensitiveFiltering)
        {
            // Following good SOA practices, verify the
              // incoming data can be worked with.

              ValidateFamilyDocument( familyDocument ); // Throws an exception if not a family doc

              // The filter can be null, the filter matching function checks for that.

            #if _2010
              List<Family> oResult = new List<Family>();

              ElementIterator it = familyDocument.Elements;

              while( it.MoveNext() )
              {
            Element oElement = it.Current as Element;

            if( ( oElement is Family )
              && FilterMatches( oElement.Name,
            familyFileNameFilter, caseSensitiveFiltering ) )
            {
              oResult.Add( oElement as Family );
            }
              }
            #endif // _2010

              FilteredElementCollector collector
            = new FilteredElementCollector( familyDocument );

              collector.OfClass( typeof( Family ) );

              IEnumerable<Element> familiesMatching =
            from f in collector
            where FilterMatches( f.Name, familyFileNameFilter, caseSensitiveFiltering )
            select f;

              return familiesMatching.Cast<Family>();
        }

Usage Example

        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);
        }