-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelIsolator.cs
162 lines (149 loc) · 4.63 KB
/
LevelIsolator.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* 由SharpDevelop创建。
* 用户: jack.tsao
* 日期: 2018/7/4
* 时间: 上午 11:31
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace MyAppMacro
{
/// <summary>
/// Description of LevelIsolator.
/// </summary>
public partial class LevelIsolator : System.Windows.Forms.Form
{
private Document m_doc;
private UIDocument m_uidoc;
private IList<Level> m_levels=null;
public LevelIsolator(Document doc, UIDocument uidoc)
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
m_doc = doc;
m_uidoc = uidoc;
m_levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().OrderBy(l => l.Elevation).ToList();
foreach (Level level in m_levels) {
cbLevel.Items.Add(level.Name);
}
cbLevel.SelectedIndex=0;
}
void BtnApplyClick(object sender, EventArgs e)
{
Level curLevel = m_levels.ElementAt(cbLevel.SelectedIndex);
//cbLevel.Text;
// TaskDialog.Show("Current selected Level", curLevel.Name);
IEnumerable<Element> Allelem= JtElementExtensionMethods.SelectAllPhysicalElements(m_doc);
List<ElementId> eIds= new List<ElementId>();
Parameter a1,a2,a3, a4, a5, a6, a7;
IEnumerator<Element> a = Allelem.GetEnumerator();
while (a.MoveNext()) {
Element e1 = a.Current;
a1 = e1.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
a2 = e1.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
a3 = e1.get_Parameter(BuiltInParameter.LEVEL_PARAM);
a4 = e1.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
a5 = e1.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
a6 = e1.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM);
a7 = e1.get_Parameter(BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM);
try
{
if (null != a1)
{
Level a1_Level = m_doc.GetElement(a1.AsElementId()) as Level;
if(a1_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a2)
{
Level a2_Level = m_doc.GetElement(a2.AsElementId()) as Level;
if(a2_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a3)
{
Level a3_Level = m_doc.GetElement(a3.AsElementId()) as Level;
if(a3_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a4)
{
Level a4_Level = m_doc.GetElement(a4.AsElementId()) as Level;
if(a4_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a5)
{
Level a5_Level = m_doc.GetElement(a5.AsElementId()) as Level;
if(a5_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a6)
{
Level a6_Level = m_doc.GetElement(a6.AsElementId()) as Level;
if(a6_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
if (null != a7)
{
Railing e2 = e1 as Railing;
if(e2.HasHost)
{
Element e3 = m_doc.GetElement(e2.HostId);
a7 = e3.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM);
}
Level a7_Level = m_doc.GetElement(a7.AsElementId()) as Level;
if(a7_Level.Id != curLevel.Id)
//m_uidoc.ActiveView.HideElementTemporary(e1.Id);
eIds.Add(e1.Id);
}
// try
// {
}
catch (Exception)
{
//TaskDialog.Show("Exception", ex.ToString());
}
}
m_uidoc.ActiveView.HideElements(eIds);
m_uidoc.RefreshActiveView();
this.Close();
}
}
public static class JtElementExtensionMethods
{
public static bool IsPhysicalElement(this Element e)
{
if( e.Category == null ) return false;
if( e.ViewSpecific ) return false;
// exclude specific unwanted categories
if( ( (BuiltInCategory) e.Category.Id.IntegerValue ) == BuiltInCategory.OST_HVAC_Zones ) return false;
return e.Category.CategoryType == CategoryType.Model && e.Category.CanAddSubcategory;
}
public static IEnumerable<Element> SelectAllPhysicalElements(Document doc)
{
return new FilteredElementCollector( doc )
.WhereElementIsNotElementType()
.Where( e => e.IsPhysicalElement() );
}
}
}