Revit Element API object carries a lot of useful information. In this post, let us look at a way to retrieve some very basic information such as element id, type, name, category, and unique id from Revit elements in a model and write it into a CSV file.
public static void RevitModelElementIds(Document doc)
{
List<ElementId> list = new List<ElementId>();
FilteredElementCollector finalCollector = new FilteredElementCollector(doc);
ElementIsElementTypeFilter filter1 = new ElementIsElementTypeFilter(false);
finalCollector.WherePasses(filter1);
ElementIsElementTypeFilter filter2 = new ElementIsElementTypeFilter(true);
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter2));
list = finalCollector.ToElementIds().OrderBy(e=>e.IntegerValue).ToList();
StringBuilder sb = new StringBuilder();
sb.AppendLine("ElementId,Type,Name,Category,UniqueId");
foreach (ElementId id in list)
{
Element e = doc.get_Element(id);
sb.AppendLine(string.Format("{0},{1},{2},{3},{4}", id.IntegerValue, e.GetType().Name, e.Name, e.Category!=null?e.Category.Name:"", e.UniqueId));
}
using (StreamWriter sw = new StreamWriter(@"c:\temp\RevitModelElementIds.csv"))
{
sw.Write(sb.ToString());
}
}
Here is the test code:
…
RevitModelElementIds(CachedDoc);
…
The following is part of output for a model:
ElementId,Type,Name,Category,UniqueId
0,Element,Project Phase Information,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000000
1,Phase,Existing,Phases,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000001
2,Element,System Data,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000002
3,Phase,New Construction,Phases,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000003
4,Element,System Data,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000004
5,Element,Halftone and Underlay Settings,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000005
6,Element,Standard,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000006
7,Element,Standard,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000007
11,Element,Revisions,Revision,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000000b
12,Element,Project Revision Information,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000000c
15,ProjectUnit,Project Units,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000000f
16,Element,Line Weights,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000010
17,FillPattern,Solid fill,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000011
18,FillPattern,Diagonal up,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000012
19,FillPattern,Diagonal down,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000013
20,FillPattern,Horizontal,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000014
21,FillPattern,Vertical,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000015
22,FillPattern,Crosshatch,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000016
23,FillPattern,Diagonal crosshatch,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000017
24,LinePattern,Long dash,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000018
25,LinePattern,Dash,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000019
26,LinePattern,Loose dash,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001a
27,LinePattern,Center,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001b
28,LinePattern,Double dash,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001c
29,LinePattern,Triple dash,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001d
30,LinePattern,Dash dot,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001e
31,LinePattern,Dash dot dot,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000001f
32,LinePattern,Dot,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000020
33,LinePattern,Overhead,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000021
34,LinePattern,Hidden,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000022
35,LinePattern,Demolished,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000023
36,LinePattern,Grid Line,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000024
37,MaterialOther,Default,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000025
38,MaterialOther,Default Wall,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000026
39,MaterialOther,Default Roof,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000027
40,MaterialOther,Glass,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000028
41,MaterialOther,Phase-Demo,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000029
42,MaterialOther,Phase-Exist,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002a
43,MaterialOther,Phase-Temp,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002b
44,MaterialOther,Poche,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002c
45,MaterialOther,Default Light Source,Materials,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002d
46,GraphicsStyle,Building Units,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002e
47,GraphicsStyle,Hidden Lines,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000002f
48,GraphicsStyle,Walls,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000030
49,GraphicsStyle,Walls,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000031
50,GraphicsStyle,Hidden Lines,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000032
51,GraphicsStyle,Hidden Lines,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000033
52,GraphicsStyle,Stacked Walls,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000034
53,GraphicsStyle,Stacked Walls,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000035
54,GraphicsStyle,Surface Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000036
55,GraphicsStyle,Surface Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000037
56,GraphicsStyle,Analytical Model,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000038
57,GraphicsStyle,Analytical Model,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000039
58,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003a
59,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003b
60,GraphicsStyle,Structure [1],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003c
61,GraphicsStyle,Structure [1],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003d
62,GraphicsStyle,Substrate [2],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003e
63,GraphicsStyle,Substrate [2],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000003f
64,GraphicsStyle,Thermal/Air Layer [3],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000040
65,GraphicsStyle,Thermal/Air Layer [3],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000041
66,GraphicsStyle,Finish 1 [4],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000042
67,GraphicsStyle,Finish 1 [4],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000043
68,GraphicsStyle,Finish 2 [5],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000044
69,GraphicsStyle,Finish 2 [5],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000045
70,GraphicsStyle,Common Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000046
71,GraphicsStyle,Common Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000047
72,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000048
73,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000049
74,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004a
75,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004b
76,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004c
77,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004d
78,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004e
79,GraphicsStyle,Cut Pattern,,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000004f
80,GraphicsStyle,Interior Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000050
81,GraphicsStyle,Interior Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000051
82,GraphicsStyle,Interior Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000052
83,GraphicsStyle,Interior Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000053
84,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000054
85,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000055
86,GraphicsStyle,Structure [1],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000056
87,GraphicsStyle,Structure [1],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000057
88,GraphicsStyle,Substrate [2],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000058
89,GraphicsStyle,Substrate [2],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000059
90,GraphicsStyle,Thermal/Air Layer [3],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005a
91,GraphicsStyle,Thermal/Air Layer [3],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005b
92,GraphicsStyle,Finish 1 [4],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005c
93,GraphicsStyle,Finish 1 [4],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005d
94,GraphicsStyle,Finish 2 [5],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005e
95,GraphicsStyle,Finish 2 [5],,618a6d33-4c87-4634-8f09-4e3b0f2db998-0000005f
96,GraphicsStyle,Common Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000060
97,GraphicsStyle,Common Edges,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000061
98,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000062
99,GraphicsStyle,Membrane Layer,,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000063
100,GraphicsStyle,Structure [1],,618a6d33-4c87-4634-8f09-4e3b0f2db998-00000064
…
If the file were opened by the Excel application, it would look nicer for sure.
RevitAddinWizard provides various wizards and coders to help program Revit Addins.
Recent Comments