1+ using Autodesk . DesignScript . Runtime ;
2+ using Autodesk . Revit . DB ;
3+ using Dynamo . Graph . Nodes ;
4+ using Revit . Elements ;
5+ using Category = Revit . Elements . Category ;
6+
7+ namespace OpenMEPRevit . Element ;
8+
9+ [ IsVisibleInDynamoLibrary ( true ) ]
10+ public class ParameterFilterElement
11+ {
12+ private ParameterFilterElement ( )
13+ {
14+ }
15+
16+ public List < Category > ? Categories ( Revit . Elements . Element parameterElement )
17+ {
18+ List < Category > categories = new List < Category > ( ) ;
19+ Autodesk . Revit . DB . ParameterFilterElement ? parameterFilterElement = parameterElement . InternalElement as Autodesk . Revit . DB . ParameterFilterElement ;
20+ ICollection < ElementId > ? elementIds = parameterFilterElement ? . GetCategories ( ) ;
21+ if ( elementIds == null )
22+ {
23+ return categories ;
24+ }
25+ #if R20 || R21 || R22 || R23
26+ foreach ( ElementId elementId in elementIds )
27+ {
28+ categories . Add ( Category . ById ( elementId . IntegerValue ) ) ;
29+ }
30+ #else
31+ foreach ( ElementId elementId in elementIds )
32+ {
33+ categories . Add ( Category . ById ( elementId . Value ) ) ;
34+ }
35+ #endif
36+ return categories ;
37+ }
38+ /// <summary>
39+ /// Return All Element Inside View Filter
40+ /// </summary>
41+ /// <param name="viewFilter"></param>
42+ /// <returns name="elements">elements get from view filter</returns>
43+ /// <example>
44+ /// 
45+ /// [View.GetAllElementByViewFilter.dyn](../OpenMEPPage/element/dyn/View.GetAllElementByViewFilter.dyn)
46+ /// </example>
47+ [ NodeCategory ( "Action" ) ]
48+ [ NodeSearchTags ( "get element" ) ]
49+ public static List < Revit . Elements . Element > GetAllElementByViewFilter ( Revit . Elements . Element viewFilter )
50+ {
51+ Autodesk . Revit . DB . Document doc = viewFilter . InternalElement . Document ;
52+ Autodesk . Revit . DB . ParameterFilterElement ? parameterFilterElement = viewFilter . InternalElement as Autodesk . Revit . DB . ParameterFilterElement ;
53+ if ( parameterFilterElement == null )
54+ return new List < Revit . Elements . Element > ( ) ;
55+ ElementFilter elementFilter = parameterFilterElement . GetElementFilter ( ) ;
56+ ICollection < ElementId > cates = parameterFilterElement . GetCategories ( ) ;
57+ IList < ElementFilter > eleFilters = new List < ElementFilter > ( ) ;
58+ foreach ( var cat in cates )
59+ {
60+ eleFilters . Add ( new ElementCategoryFilter ( cat ) ) ;
61+ }
62+ var cateFilter = new LogicalOrFilter ( eleFilters ) ;
63+ if ( elementFilter != null )
64+ {
65+ return new FilteredElementCollector ( doc )
66+ . WhereElementIsNotElementType ( )
67+ . WhereElementIsViewIndependent ( )
68+ . WherePasses ( cateFilter )
69+ . WherePasses ( elementFilter )
70+ . ToElements ( ) . Select ( x => x . ToDSType ( true ) ) . ToList ( ) ;
71+ }
72+ return new FilteredElementCollector ( doc )
73+ . WhereElementIsNotElementType ( )
74+ . WhereElementIsViewIndependent ( )
75+ . WherePasses ( cateFilter )
76+ . ToElements ( ) . Select ( x => x . ToDSType ( true ) ) . ToList ( ) ;
77+ }
78+ }
0 commit comments