-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreports.py
367 lines (308 loc) · 12.3 KB
/
reports.py
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import os
import csv
from Autodesk.Revit.DB import BuiltInCategory
from Autodesk.Revit.DB import BuiltInParameter
from Autodesk.Revit.DB import ElementId
from Autodesk.Revit.DB import ElementMulticategoryFilter
from Autodesk.Revit.DB import ElementTypeGroup
from Autodesk.Revit.DB import Family
from Autodesk.Revit.DB import FamilyInstance
from Autodesk.Revit.DB import FamilySymbol
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import Level
from Autodesk.Revit.DB import LinePatternElement
from Autodesk.Revit.DB import ParameterFilterElement
from Autodesk.Revit.DB import TextNote
from Autodesk.Revit.DB import View
from Autodesk.Revit.DB import ViewType
from Autodesk.Revit.DB import ViewSheet
from Autodesk.Revit.DB import XYZ
from System.Collections.Generic import List
import lib
from api import *
import constants
def families_report(doc):
"""Generate report of families"""
with open(os.path.join(constants.HOMEDIR, '{} - families.csv'.format(doc.Title)), 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(('Category', 'Family'))
for family in FilteredElementCollector(doc).OfClass(Family):
try:
w.writerow((family.FamilyCategory.Name, family.Name))
except:
print(family)
def view_template_report(doc):
"""Generate csv report of View Templates and their Category visibility"""
views = FilteredElementCollector(doc).OfClass(View)
rows = []
templates = set()
for view in views:
if view.ViewTemplateId != ElementId.InvalidElementId:
templates.add(view.ViewTemplateId)
for template_id in templates:
template = doc.GetElement(template_id)
print(template.Name)
for cat in doc.Settings.Categories:
try:
rows.append((
template.Name,
str(cat.CategoryType).split('.')[-1],
cat.Name,
cat.get_Visible(template)
))
except:
pass
csv_name = os.path.join(constants.HOMEDIR, '{} - View Templates.csv'.format(doc.Title))
with open(csv_name, 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(('View Template', 'Type', 'Category', 'Visible'))
w.writerows(rows)
def sheet_report(doc):
"""Report on sheets"""
sheets = [x for x in FilteredElementCollector(doc).OfClass(ViewSheet)
if x.LookupParameter('Identifier_TX').AsString() == 'RLS']
with lib.transaction(doc, 'Add sheets to schedule'):
for sheet in sheets:
scheduled_param = sheet.get_Parameter(BuiltInParameter.SHEET_SCHEDULED)
if not scheduled_param.AsInteger():
print(sheet.SheetNumber)
scheduled_param.Set(1)
def get_door_window_walls(doc):
"""Report all doors or windows with hosted wall types"""
categories = List[BuiltInCategory]()
categories.Add(BuiltInCategory.OST_Doors)
categories.Add(BuiltInCategory.OST_Windows)
categories_filter = ElementMulticategoryFilter(categories)
elements = FilteredElementCollector(doc).OfClass(FamilyInstance).WherePasses(categories_filter)
level_map = {}
rows = []
for element in elements:
wall = element.Host
if not wall:
continue
if not wall.WallType:
continue
level_id = element.LevelId
level = level_map.get(level_id)
if not level:
level = doc.GetElement(level_id)
level_map[level_id] = level
rows.append([
element.Category.Name,
level.Name,
element.Symbol.FamilyName,
element.Name,
element.Symbol.LookupParameter('Descriptor_TX').AsString() or '',
element.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString(),
wall.WallType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString(),
wall.WallType.LookupParameter('Wall_Mark_TX').AsString() or '',
wall.WallType.Width * constants.MM,
])
csv_name = os.path.join(constants.HOMEDIR, '{} - DoorsWindows.csv'.format(doc.Title))
with open(csv_name, 'w') as f:
writer = csv.writer(f, lineterminator='\n')
writer.writerow([
'Category',
'Level',
'Family',
'Type',
'Code',
'Mark',
'Wall Type',
'Wall Code',
'Wall Width',
])
writer.writerows(rows)
def export_rooms_csv(doc):
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
with open('rooms.csv', 'w') as f:
w = csv.writer(f)
w.writerow(['ID', 'Number', 'Name', 'Level'])
for room in rooms:
w.writerow([
room.Id,
room.Number,
room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString(),
room.Level.Name])
print 'Done'
def import_rooms_csv(doc):
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
id_map = {}
csvpath = r'I:\NBIF\Projects\NB98100\Deliverables\BIM\01_Architecture\A_WIP Models\rooms_updated.csv'
with open(csvpath) as f:
for row in csv.DictReader(f, ):
id_map[row['ID']] = row
tr = Transaction(doc, "Change room numbers")
tr.Start()
with open('rooms_changed.csv', 'w') as f:
w = csv.writer(f)
w.writerow(['ID', 'Name', 'Old Number', 'New Number', 'Level'])
for room in rooms:
id_row = id_map.get(str(room.Id))
if id_row:
assert id_row['Level'] not in ['Level 1', 'Level 4', 'Level 5']
old_number = room.Number
room.Number = id_row['Number']
print '{} - {} -> {}'.format(room.Id, old_number, room.Number)
w.writerow([
room.Id,
room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString(),
old_number,
room.Number,
room.Level.Name])
tr.Commit()
def list_doors():
doors = FilteredElementCollector(doc)\
.OfClass(FamilyInstance)\
.OfCategory(BuiltInCategory.OST_Doors)
print 'ID Mark ToRoom FromRoom'
print '-- ------- ------- --------'
for door in doors:
phase = doc.GetElement(door.CreatedPhaseId)
try:
to_room = door.ToRoom[phase]
from_room = door.FromRoom[phase]
door_mark = door.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString()
to_room_number = None
from_room_number = None
if to_room:
to_room_number = to_room.Number
if from_room:
from_room_number = from_room.Number
print '{}\t{}\t{}\t{}'.format(door.Id, door_mark[:7], to_room_number, from_room_number)
except:
pass
print
def list_text():
elements = FilteredElementCollector(doc).OfClass(TextElement)
for x in elements:
print x.Text
def export_families(doc):
"""Generate report of loaded families and types"""
symbols = FilteredElementCollector(doc).OfClass(FamilySymbol)
with open(os.path.join(constants.HOMEDIR, 'report.csv'), 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(['Category', 'Family', 'Type', 'Descriptor_TX', 'BIM ID'])
for symbol in symbols:
name = symbol.get_Parameter(
BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
family = symbol.Family.Name
category = symbol.Category.Name
dtx_param = symbol.LookupParameter('Descriptor_TX')
dtx = ''
if dtx_param:
dtx = dtx_param.AsString()
bim_id_param = symbol.LookupParameter('BIM ID')
if bim_id_param:
bim_id = bim_id_param.AsString()
else:
bim_id = ''
w.writerow([category, family, name, dtx, bim_id])
def parameter_report(doc):
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
definition = iterator.Key
binding = iterator.Current
print definition.Name, definition.ParameterType, definition.ParameterGroup, definition.UnitType
#for category in binding.Categories:
# print category.Name
def offsets_report(doc):
out = []
for instance in FilteredElementCollector(doc).OfClass(FamilyInstance):
offset = instance.get_Parameter(
BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM
).AsDouble() * constants.MM
#if offset < 0:
out.append((
instance.Id.IntegerValue,
instance.Symbol.Category.Name,
instance.Symbol.Family.Name,
instance.Symbol.get_Parameter(
BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString(),
doc.GetElement(instance.LevelId).Name if instance.LevelId != ElementId.InvalidElementId else '',
offset,
))
with open(os.path.join(HOMEDIR, 'offsets.csv'), 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(['ID', 'Category', 'Family', 'Type', 'Level', 'Offset'])
w.writerows(out)
def view_filter_report(doc):
"""
Generate a csv of the form [View, Template Name, View Filter Name] for all
views that support filters
"""
view_types = [
ViewType.AreaPlan,
ViewType.CeilingPlan,
ViewType.Elevation,
ViewType.FloorPlan,
ViewType.Section,
ViewType.ThreeD,
]
with open(os.path.join(constants.HOMEDIR, 'filters.csv'), 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(['View', 'Template', 'Filter'])
for flt in FilteredElementCollector(doc).OfClass(ParameterFilterElement):
w.writerow(['', '', flt.Name])
for view in FilteredElementCollector(doc).OfClass(View):
if view.ViewType not in view_types:
continue
if view.ViewTemplateId != ElementId.InvalidElementId:
template_name = doc.GetElement(view.ViewTemplateId).Name
else:
template_name = ''
try:
for fid in view.GetFilters():
fl = doc.GetElement(fid)
w.writerow([view.Name, template_name, fl.Name])
except:
print(view.Name, view.ViewType)
def views_report(doc):
with open(os.path.join(HOMEDIR, 'views_on_sheets.csv'), 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(('Sheet Number', 'Sheet Name', 'View Name', 'View Type'))
for sheet in FilteredElementCollector(doc).OfClass(ViewSheet):
for view in FilteredElementCollector(doc, sheet.Id).OfClass(View):
w.writerow((sheet.SheetNumber, sheet.Name, view.Name, view.ViewType))
def element_report(doc):
"""
Generate csv report of all family instances in document including workset
and category
"""
elements = FilteredElementCollector(doc).OfClass(FamilyInstance)
levels = {}
worksets = {}
workset_table = doc.GetWorksetTable()
out = []
for element in elements:
if element.LevelId.IntegerValue in levels:
level = levels[element.LevelId.IntegerValue]
else:
if element.LevelId == ElementId.InvalidElementId:
level = ''
else:
level = doc.GetElement(element.LevelId).Name
levels[element.LevelId.IntegerValue] = level
workset_id = doc.GetWorksetId(element.Id)
workset = workset_table.GetWorkset(workset_id).Name
mark_param = element.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
if mark_param:
mark = mark_param.AsString()
else:
mark = ''
try:
out.append((
element.Id.IntegerValue,
mark,
workset,
element.Symbol.Category.Name,
element.Symbol.Family.Name,
level
))
except Exception as e:
print(e, element)
csvfile = lib.get_temp_path('element_report.csv')
with open(csvfile, 'w') as f:
w = csv.writer(f, lineterminator='\n')
w.writerow(('ID', 'Mark', 'Workset', 'Category', 'Family', 'Level'))
w.writerows(out)