-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.cs
More file actions
51 lines (43 loc) · 1.61 KB
/
Utils.cs
File metadata and controls
51 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
namespace MyRevitCommands
{
internal static class Utils
{
/// <summary>
/// Helper to get all instances for a given category,
/// identified either by a built-in category or by a category name.
/// </summary>
public static List<Element> GetTargetInstances(
Document doc,
object targetCategory)
{
List<Element> elements;
var isName = targetCategory.GetType().Equals(typeof(string));
if (isName)
{
var cat = doc.Settings.Categories.get_Item(targetCategory as string);
var collector = new FilteredElementCollector(doc);
collector.OfCategoryId(cat.Id);
elements = new List<Element>(collector);
}
else
{
var collector
= new FilteredElementCollector(doc)
.WhereElementIsNotElementType();
collector.OfCategory((BuiltInCategory) targetCategory);
// I removed this to test attaching a shared
// parameter to Material elements:
//
//var model_elements = from e in collector
// where ( null != e.Category && e.Category.HasMaterialQuantities )
// select e;
//elements = model_elements.ToList<Element>();
elements = collector.ToList();
}
return elements;
}
}
}