-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
263 lines (217 loc) · 9.2 KB
/
Copy pathviews.py
File metadata and controls
263 lines (217 loc) · 9.2 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
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
import re
from Autodesk.Revit.DB import BuiltInCategory
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import ParameterFilterElement
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.DB import View
from Autodesk.Revit.DB import ViewType
from lib import transaction
from api import *
def set_has_layout(doc):
pat = re.compile('^(\d{4}) - ')
plans = (x for x in FilteredElementCollector(doc).OfClass(View) if x.ViewType == ViewType.FloorPlan)
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
room_map = {}
for room in rooms:
room_map[room.Number] = room
tr = Transaction(doc, 'Set HasLayout')
tr.Start()
for plan in plans:
bits = pat.findall(plan.Name)
if len(bits) == 1:
room_num = bits[0]
room = room_map.get(room_num)
if room:
room.LookupParameter('HasLayout_YN').Set(True)
print(room)
tr.Commit()
def fix_view_templates(doc):
dw = DocumentWrapper(doc)
tr = Transaction(doc, 'Fix views templates')
tr.Start()
for vt in dw.view_templates:
param = vt.LookupParameter(constants.IDENTIFIER_PARAM)
#if param.AsString() == 'PLOT_':
if param:
param.Set('PLOT')
print(vt.Name)
tr.Commit()
def rename_filters(doc):
"""Rename View Filters with '(1)' at the end of the name"""
pat = re.compile('(.*)\(\d\)$')
filters = FilteredElementCollector(doc).OfClass(ParameterFilterElement)
with transaction(doc, 'Rename filters'):
for f in filters:
bits = pat.findall(f.Name)
if bits:
f.Name = bits[0].strip()
print(f.Name)
def view_params(doc):
view = doc.ActiveView
fields = {}
for param in view.Parameters:
fields[param.Definition.Name] = get_param_value(param, doc)
pprint(fields)
def swap_view_templates(doc, from_name, to_name):
all_views = [x for x in FilteredElementCollector(doc).OfClass(View) if not x.IsTemplate]
all_templates = [x for x in FilteredElementCollector(doc).OfClass(View) if x.IsTemplate]
from_template = [x for x in all_templates if x.Name == from_name][0]
to_template = [x for x in all_templates if x.Name == to_name][0]
with transaction(doc, "Swap view templates"):
for view in all_views:
if view.ViewTemplateId == from_template.Id:
view.ViewTemplateId = to_template.Id
print(view.Name)
def fix_schedules(doc):
pat = re.compile('(\d{4})')
schedules = [x for x in FilteredElementCollector(doc).OfClass(View)
if x.ViewType == ViewType.Schedule and 'fitout' in x.Name.lower()]
levels = list(FilteredElementCollector(doc).OfClass(Level))
with transaction(doc, "Fix schedules"):
for schedule in schedules:
# Get room name from schedule name
bits = pat.findall(schedule.Name)
room_name = None
if bits:
room_name = bits[0]
else:
continue
# Check if level field already added
stop = False
fields = [schedule.Definition.GetField(x) for x in
schedule.Definition.GetFieldOrder()]
for f in fields:
if f.GetName() == 'Level':
stop = True
if stop:
print('{} has Level field'.format(schedule.Name))
continue
# Add level field
field = None
for sf in schedule.Definition.GetSchedulableFields():
if sf.GetName(doc) == 'Level':
field = schedule.Definition.AddField(sf)
if not field:
continue
field.IsHidden = True
# Get level to filter by
level_num = room_name[0]
level = [x for x in levels if x.Name == 'LEVEL ' + level_num][0]
# Add level filter
filters = list(schedule.Definition.GetFilters())
level_filter = ScheduleFilter(
field.FieldId, ScheduleFilterType.Equal, level.Id)
filters.insert(0, level_filter)
schedule.Definition.SetFilters(filters)
print(schedule.Name)
def rename_schedules(doc):
pat = re.compile('(FITOUT)[- ]+(\d{4})[- ]+(.*)', re.IGNORECASE)
schedules = [x for x in FilteredElementCollector(doc).OfClass(View)
if x.ViewType == ViewType.Schedule and 'fitout' in x.Name.lower()]
with transaction(doc, 'Fix schedule titles'):
for schedule in schedules:
match = pat.findall(schedule.Name)
if match:
bits = match[0]
new_name = '{} - {} - {}'.format(*bits).upper()
try:
if schedule.Name != new_name:
schedule.Name = new_name
except:
print(schedule.Name, new_name)
def rename_elevations(doc):
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
room_map = {
x.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString():
x.get_Parameter(BuiltInParameter.ROOM_NAME).AsString() for x in rooms}
views = [x for x in FilteredElementCollector(doc).OfClass(View)
if x.ViewType == ViewType.FloorPlan]
#for elev in elevations:
# identifierParam = elev.LookupParameter(constants.IDENTIFIER_PARAM)
# descriptorParam = elev.LookupParameter(constants.DESCRIPTOR_TX)
# if identifierParam and \
# identifierParam.AsString() == 'PLOT' and \
# descriptorParam and \
# descriptorParam.AsString():
# print(elev.Name)
#pat = re.compile('(\d{4})_(\d)')
pat = re.compile('^(\d{4})+')
with transaction(doc, 'Rename views'):
for view in views:
bits = pat.findall(view.Name)
if bits:
number = bits[0]
name = room_map.get(number, 'XXX')
print(view.Name, '{} - {} - PLAN'.format(','.join(bits), name))
def fix_view_names(doc):
with transaction(doc, 'Rename views'):
for view in FilteredElementCollector(doc).OfClass(View):
title_param = view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION)
sheet_param = view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NUMBER)
if sheet_param.AsString() and title_param.AsString().strip() and sheet_param.AsString().startswith('RM'):
#print(title_param.AsString(), sheet_param.AsString())
print(view.Name)
title_param.Set('')
def rename_zone_views(doc):
pat = re.compile(r'RCP - LEVEL (\d) - 1-(\d{2,3}) Zone (\d)')
views = [x for x in FilteredElementCollector(doc).OfClass(View) if x.ViewType == ViewType.CeilingPlan]
with transaction(doc, "Rename views"):
for view in views:
bits = pat.findall(view.Name)
if bits:
bits = bits[0]
new_name = 'RCP_{}_{}_Z{}'.format(*bits)
view.Name = new_name
print(view.Name)
def fix_scope_boxes(doc):
dw = DocumentWrapper(doc)
scope_box_map = {x.Name: x for x in dw.scope_boxes}
tr = Transaction(doc, 'Apply scope boxes to zone views')
tr.Start()
for view in dw.views:
if 'Zone' in view.Name:
scope_box_param = view.LookupParameter('Scope Box')
if not scope_box_param:
continue
scope_box_name = scope_box_param.AsValueString()
if scope_box_name == 'None':
bits = re.findall('Zone (\d)$', view.Name)
if not bits:
continue
new_scope_box_name = '1-{} Zone {}'.format(view.Scale, bits[0])
new_scope_box = scope_box_map[new_scope_box_name]
scope_box_param.Set(new_scope_box.Id)
print(view.Name, scope_box_param.AsValueString())
tr.Commit()
def rename_scope_boxes(doc):
scope_boxes = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest)
tr = Transaction(doc, 'Rename scope boxes')
tr.Start()
for box in scope_boxes:
new_name = box.Name.rstrip(' Scope Box')
box.get_Parameter(BuiltInParameter.VOLUME_OF_INTEREST_NAME).Set(new_name)
print(new_name)
tr.Commit()
def delete_unused_scope_boxes(doc):
"""Delete scope boxes that are not used in any views"""
all_views = FilteredElementCollector(doc).OfClass(View)
all_scope_boxes = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest)
all_scope_box_ids = set(x.Id for x in all_scope_boxes)
used_scope_box_ids = set()
for view in all_views:
try:
used_scope_box_ids.add(
view.get_Parameter(
BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP
).AsElementId())
except:
pass
count = 0
unused_scope_box_ids = all_scope_box_ids.difference(used_scope_box_ids)
with transaction(doc, "Delete unused scope boxes"):
for id in unused_scope_box_ids:
scope_box = doc.GetElement(id)
print(scope_box.Name)
doc.Delete(id)
count += 1
print('{} scope boxes deleted'.format(count))