-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworksets.py
More file actions
80 lines (61 loc) · 2.61 KB
/
worksets.py
File metadata and controls
80 lines (61 loc) · 2.61 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
"""Functions related to worksets"""
from Autodesk.Revit.DB import BuiltInParameter
from Autodesk.Revit.DB import FamilyInstance
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import FilteredWorksetCollector
from Autodesk.Revit.DB import WorksetKind
from lib import transaction
def get_hosted_workset(instance):
return instance.Host.WorksetId
CATEGORY_WORKSETS = {
'Casework': lambda x: 'A_FFE',
'Stairs': lambda x: 'A_Core',
#'Ceilings': lambda x: 'A_Interior',
'Electrical Equipment': lambda x: 'A_FFE',
'Electrical Fixtures': lambda x: 'A_FFE',
'Furniture': lambda x: 'A_FFE',
'Furniture Systems': lambda x: 'A_FFE',
'Lighting Fixtures': lambda x: 'A_FFE',
'Nurse Call Devices': lambda x: 'A_FFE',
'Floors': lambda x: 'A_Structure',
'Structural Columns': lambda x: 'A_Structure',
'Structural Framing': lambda x: 'A_Structure',
'Windows': get_hosted_workset,
'Doors': get_hosted_workset,
'Specialty Equipment': lambda x: 'A_FFE',
'Roofs': lambda x: 'A_Envelope',
}
STOP_WORKSETS = ['A_StructureEarlyWorks']
def fix_worksets(doc):
"""Apply correct worksets to elements based on their category"""
workset_table = doc.GetWorksetTable()
worksets = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)
workset_map = {x.Name: x.Id.IntegerValue for x in worksets}
elements = FilteredElementCollector(doc).OfClass(FamilyInstance)
count = 0
with transaction(doc, 'Fix worksets'):
for element in elements:
category = element.Symbol.Category.Name
ws_getter = CATEGORY_WORKSETS.get(category)
if not ws_getter:
continue
new_workset = ws_getter(element)
if not new_workset:
continue
# new_workset can be either the workset name or the workset id
if not isinstance(new_workset, str):
new_workset = workset_table.GetWorkset(new_workset).Name
workset_id = doc.GetWorksetId(element.Id)
workset = workset_table.GetWorkset(workset_id).Name
if workset in STOP_WORKSETS:
continue
if workset != new_workset:
workset_param = element.get_Parameter(
BuiltInParameter.ELEM_PARTITION_PARAM)
if workset_param.IsReadOnly:
continue
workset_param.Set(workset_map.get(new_workset))
count += 1
if count and not count % 10:
print('{} changed'.format(count))
print('Total of {} elements changed'.format(count))