|
10 | 10 | from Autodesk.Revit.DB import BuiltInCategory, ElementMulticategoryFilter, FilteredElementCollector, Opening, SelectionFilterElement, Transaction, ElementId
|
11 | 11 |
|
12 | 12 | # pyRevit
|
13 |
| -from pyrevit import script |
| 13 | +from pyrevit import revit, script |
14 | 14 | from pyrevit.framework import List
|
15 | 15 | doc =__revit__.ActiveUIDocument.Document
|
16 | 16 | uidoc =__revit__.ActiveUIDocument
|
|
57 | 57 | all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
|
58 | 58 | dict_sel_filters = {f.Name: f for f in all_sel_filters}
|
59 | 59 |
|
60 |
| -try: |
61 |
| - t = Transaction(doc, 'Create Openings Filter') |
62 |
| - t.Start() |
63 |
| - |
64 |
| - # Selection Filter Name |
| 60 | +# Transaction to create a new selection filter |
| 61 | +with revit.Transaction('Create Openings Filter'): |
65 | 62 | new_filter_name = '0_ShaftOpenings'
|
66 |
| - |
67 |
| - # Create new if doesn't exist |
68 | 63 | if new_filter_name not in dict_sel_filters:
|
69 | 64 | new_fil = SelectionFilterElement.Create(doc, new_filter_name)
|
70 | 65 | new_fil.AddSet(element_ids)
|
71 | 66 | print ('Created a filter called : {}'.format(new_filter_name))
|
72 |
| - |
73 |
| - # Update if already exists |
74 | 67 | else:
|
75 | 68 | existing_fil = dict_sel_filters[new_filter_name]
|
76 | 69 | existing_fil.AddSet(element_ids)
|
77 | 70 | print ('Updated a filter called : {}'.format(new_filter_name))
|
78 | 71 |
|
79 |
| - t.Commit() |
80 |
| -except Exception as ex: |
81 |
| - if t.HasStarted(): |
82 |
| - t.RollBack() |
83 |
| - script.exit(str(ex)) |
84 |
| - |
85 | 72 | # Report
|
86 |
| - |
87 | 73 | output.print_md("#### There are {} openings (floor, wall, shaft, roof) in the project.".format(len(all_elements))) # TO DO Output link for all.
|
88 | 74 | if data:
|
89 | 75 | output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])
|
|
0 commit comments