File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Pass Category and Class as Variables
3+ This snippet shows how to programatically extract the BuiltInCategory and Class Type
4+ information from an element and pass it to a FilteredElementCollector
5+
6+ It is useful when working with generic elements without knowing their category or class ahead of time
7+ or as a demonstration of BuiltInCategory and typeof(System.Type) concepts
8+
9+ TESTED REVIT API: 2017
10+ The snippet can be used as is in a Revit Application Macro for test purposes
11+
12+ Author: Deyan Nenov | github.com/ArchilizerLtd
13+
14+ This file is shared on www.revitapidocs.com
15+ For more information visit http://github.com/gtalarico/revitapidocs
16+ License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md
17+ */
18+
19+ public void PassCategoryAndClassAsVariables ( )
20+ {
21+ UIDocument uidoc = this . ActiveUIDocument ;
22+ Document doc = uidoc . Document ;
23+
24+ var element = doc . GetElement ( uidoc . Selection . PickObject ( ObjectType . Element , "Pick test subject" ) . ElementId ) ;
25+ var type = element . GetType ( ) ; //if a Wall element is picked, this substiutes *typeof(Wall)*
26+ var bic = ( BuiltInCategory ) element . Category . Id . IntegerValue //if a Wall element is picked, this substitutes *BuiltInCategory.OST_Walls*
27+
28+ FilteredElementCollector collector
29+ = new FilteredElementCollector( doc ) ;
30+
31+ collector . OfCategory ( bic ) ;
32+ collector . OfClass ( type ) ;
33+
34+ // Select all elements of the same Category and Class
35+ uidoc . Selection. SetElementIds( collector . ToElementIds ( ) ) ;
36+ }
You can’t perform that action at this time.
0 commit comments