123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using Autodesk.Revit.DB;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- public static class DocumentExtension
- {
- #region 过滤
- public static List<Element> GetElements(this Document doc, ElementFilter filter)
- {
- var collector = new FilteredElementCollector(doc);
- return collector.WherePasses(filter).ToList<Element>();
- }
- public static List<T> GetElements<T>(this Document doc) where T : Element
- {
- var collector = new FilteredElementCollector(doc);
- collector.OfClass(typeof(T));
- return collector.OfType<T>().ToList<T>();
- }
- public static List<T> GetElementTypes<T>(this Document doc, ElementFilter filter) where T : ElementType
- {
- var collector = new FilteredElementCollector(doc);
- collector.WherePasses(filter);
- collector.WhereElementIsElementType();
- collector.OfClass(typeof(T));
- return collector.OfType<T>().ToList<T>();
- }
- #endregion
- public static ElementType GetElementType(this Document doc, string typeName)
- {
- var types = doc.GetElements<ElementType>();
- return types.FirstOrDefault(type => type != null && type.Name == typeName);
- }
- }
- }
|