-
Notifications
You must be signed in to change notification settings - Fork 9
/
Database.cs
67 lines (61 loc) · 2.41 KB
/
Database.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Diagnostics;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using OpenMEPRevit.Helpers;
using RevitServices.Persistence;
namespace OpenMEPRevit.Application;
public class Database
{
private Database()
{
}
/// <summary>
/// Snoop Explore Elements
/// </summary>
/// <param name="elements">elements need to snoop</param>
/// <returns name="string">result</returns>
/// <example>
/// ![](../OpenMEPPage/application/dyn/pic/Database.SnoopElements.png)
/// [Database.SnoopElements.dyn](../OpenMEPPage/application/dyn/Database.SnoopElements.dyn)
/// </example>
public static string SnoopElements(List<global::Revit.Elements.Element> elements)
{
ICollection<ElementId> elementIds = elements.Select(x => x.InternalElement.Id).ToList();
DocumentManager.Instance.CurrentUIDocument.Selection.SetElementIds(elementIds);
RevitCommandId lookupCommandId = RevitCommandId.LookupCommandId("CustomCtrl_%CustomCtrl_%Add-Ins%Explorer%RevitDBExplorer.Command");
if(lookupCommandId == null)
{
TaskDialog.Show("Error", "Please install RevitDBExplorer");
Process.Start("https://github.com/NeVeSpl/RevitDBExplorer");
return "Please install RevitDBExplorer";
}
// execute the command
DocumentManager.Instance.CurrentUIApplication.PostCommand(lookupCommandId);
return "Success";
}
/// <summary>
/// Snoop Explore Elements By Id
/// </summary>
/// <param name="id">id of element</param>
/// <returns></returns>
/// <example>
/// ![](../OpenMEPPage/application/dyn/pic/Database.SnoopElementById.png)
/// [Database.SnoopElementById.dyn](../OpenMEPPage/application/dyn/Database.SnoopElementById.dyn)
/// </example>
public static string SnoopElementById(List<string> id)
{
Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
List<global::Revit.Elements.Element> elements = new List<global::Revit.Elements.Element>();
foreach (string s in id)
{
#if R20 || R21 || R22 || R23
ElementId elementId = new ElementId(int.Parse(s));
#else
ElementId elementId = new ElementId(long.Parse(s));
#endif
global::Revit.Elements.Element element = document.GetElement(elementId).ToDynamoType();
elements.Add(element);
}
return SnoopElements(elements);
}
}