-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAUDIT_Count_2DElementsByView.py
More file actions
137 lines (124 loc) · 5.24 KB
/
AUDIT_Count_2DElementsByView.py
File metadata and controls
137 lines (124 loc) · 5.24 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
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
#========================================================================#
# _____ __
# \_ \__ _ _ __ \ \ __ _ _ __ ___ ___ ___
# / /\/ _` | '_ \ \ \/ _` | '_ ` _ \ / _ \/ __|
# /\/ /_| (_| | | | | /\_/ / (_| | | | | | | __/\__ \
# \____/ \__,_|_| |_| \___/ \__,_|_| |_| |_|\___||___/
#
#
# The Script identifies 2D Elements in Views, and lists the views
# ordered by the Total 2D Element
#
# 2D Element Considered are:
# [1] 2D Detail Lines
# [2] Filled Regions
# [3] Masking Regions
# [4] Text Notes
#
# Feb 2020
#
#========================================================================#
#----------------------------------------------------
# Constant Values for indices
#----------------------------------------------------
INDEX_TOTAL = 0
INDEX_DETAILLINES = 1
INDEX_FILLEDREGIONS = 2
INDEX_MASKINGREGIONS = 3
INDEX_TEXTNOTES = 4
#----------------------------------------------------
# Function for sorting by Total 2D Element Count
#----------------------------------------------------
def by_Total(item):
return item[1][INDEX_TOTAL]
#----------------------------------------------------
#Get the detail Lines
theLines = (
FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Lines)
)
detailLines = (theLines
.Where(lambda l: 'Yes'.Equals(l.LookupParameter('Detail Line').AsValueString()))
)
#----------------------------------------------------
#Get the FilledRegions & Masking Regions
Regions = (
FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_DetailComponents)
.Where(lambda fr: FilledRegion == type(fr))
)
Masking = Regions.Where(lambda fr: 'Masking Region'.Equals(fr.LookupParameter('Type Name').Element.Name))
Filled = Regions.Where(lambda fr: 'Detail Filled Region'.Equals(fr.LookupParameter('Type Name').Element.Name))
#----------------------------------------------------
#Get the 2D Text Notes
TextNotes = (
FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_TextNotes)
)
#----------------------------------------------------
theViews = {}
#Count the 2D Detail Lines
for dl in detailLines:
viewId = dl.OwnerViewId
if not viewId in theViews:
#Add the View to the dict and set the line count to 1
theViews.Add(viewId,[0,1,0,0,0])
else:
# Increment the count of lines for this view
#Index [INDEX_DETAILINES] = 2D Lines
theViews[viewId][INDEX_DETAILLINES] += 1
#Overlay the Filled Regions
for fr in Filled:
viewId = fr.OwnerViewId
if not viewId in theViews:
#Add the View to the dict and set the Filled Region count to 1
theViews.Add(viewId,[0,0,1,0,0])
else:
# Increment the count of Filled Regions for this view
#Index [INDEX_FILLEDREGIONS] = Filled Regions
theViews[viewId][INDEX_FILLEDREGIONS] += 1
#Overlay the Masking Regions
for mr in Masking:
viewId = mr.OwnerViewId
if not viewId in theViews:
#Add the View to the dict and set the Filled Region count to 1
theViews.Add(viewId,[0,0,0,1,0])
else:
# Increment the count of Filled Regions for this view
#Index [INDEX_MASKINGREGIONS] = Masking Regions
theViews[viewId][INDEX_MASKINGREGIONS] += 1
#Overlay 2D Text
for tx in TextNotes:
viewId = tx.OwnerViewId
if not viewId in theViews:
#Add the View to the dict and set the Filled Region count to 1
theViews.Add(viewId,[0,0,0,0,1])
else:
# Increment the count of Filled Regions for this view
#Index [INDEX_MASKINGREGIONS] = Masking Regions
theViews[viewId][INDEX_TEXTNOTES] += 1
#Sum up all of the 2D elements into the total of each dict element
for aView in theViews:
theViews[aView][INDEX_TOTAL] = (theViews[aView][INDEX_DETAILLINES] + theViews[aView][INDEX_FILLEDREGIONS] + theViews[aView][INDEX_MASKINGREGIONS] + theViews[aView][INDEX_TEXTNOTES])
#Sort the dictionary by Total 2D Element Most to Fewest
sortedViews = sorted(theViews, key=lambda v: theViews[v][INDEX_TOTAL], reverse=True)
# Print the Table Header
print '+---------+---------+---------+---------+---------+-----------+------------+--------------------------------------+'
print '|TOTAL 2D | DETAL | FILLED | MASKING | TEXT | VIEWID | VIEW | VIEW NAME'
print '|ELEMENTS | LINES | REGIONS | REGIONS | NOTES | | TYPE |'
print '+---------+---------+---------+---------+---------+-----------+------------+--------------------------------------+'
for aView in sortedViews:
#Convert the numbers to justified strings
theTotal = theViews[aView][INDEX_TOTAL].ToString().rjust(8)
detlines = theViews[aView][INDEX_DETAILLINES].ToString().rjust(8)
filledrg = theViews[aView][INDEX_FILLEDREGIONS].ToString().rjust(8)
maskingr = theViews[aView][INDEX_MASKINGREGIONS].ToString().rjust(8)
textnote = theViews[aView][INDEX_TEXTNOTES].ToString().rjust(8)
viewId = aView.ToString().rjust(10)
viewname = Element.Name.GetValue(doc.GetElement(aView))
v = doc.GetElement(aView)
viewtype = v.Title [:v.Title.find(':')].replace('View','').ljust(10)
#Print each data row for each view
print '|' + theTotal + ' |' + detlines + ' |' + filledrg + ' |' + maskingr + ' |' + textnote + ' |' + viewId + ' | ' + viewtype + ' | ' + viewname
#Close the bottom of the table output
print '+---------+---------+---------+---------+---------+-----------+---------------------------------------------------+'