using Autodesk.Revit.DB; using DevExpress.XtraPrinting.Export.Pdf; using HStation.RevitDev.RevitDataExport.Utility; using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace HStation.RevitDev.RevitDataExport.Service { public class SearchService { public static List SearchElements(Document doc, Type type, string nameFilter, BuiltInCategory cate = BuiltInCategory.INVALID) { if (doc == null) { return null; } FilteredElementCollector collector = new FilteredElementCollector(doc); if(cate != BuiltInCategory.INVALID) { collector = collector.OfCategory(cate); } if(type != null) { collector = collector.OfClass(type); } List result = new List(); if (!string.IsNullOrEmpty(nameFilter)) { nameFilter = RegexUtils.FormatPatternString(nameFilter); IList elems = collector.ToElements(); foreach (Element elem in elems) { if (elem != null) { string name = elem.Name; Regex regex = new Regex(nameFilter); Match isMatch = regex.Match(name); if (isMatch != null && isMatch.Success) { result.Add(elem); } } } } return result; } } }