Skip to content

Commit 4afeb23

Browse files
authored
Merge pull request gtalarico#9 from ArchilizerLtd/master
added 'Snippets_PassCategoryAndClassAsVariables.cs' to 1-csharp-code
2 parents e524e01 + 5d5afce commit 4afeb23

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)