Skip to content

Commit da2fd29

Browse files
author
EF
committed
Resolved last suggestion about simplified transaction.
1 parent 926af69 commit da2fd29

File tree

1 file changed

+3
-17
lines changed
  • extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Analyse.pulldown/Get Openings.pushbutton

1 file changed

+3
-17
lines changed

extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Analyse.pulldown/Get Openings.pushbutton/script.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from Autodesk.Revit.DB import BuiltInCategory, ElementMulticategoryFilter, FilteredElementCollector, Opening, SelectionFilterElement, Transaction, ElementId
1111

1212
# pyRevit
13-
from pyrevit import script
13+
from pyrevit import revit, script
1414
from pyrevit.framework import List
1515
doc =__revit__.ActiveUIDocument.Document
1616
uidoc =__revit__.ActiveUIDocument
@@ -57,33 +57,19 @@
5757
all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
5858
dict_sel_filters = {f.Name: f for f in all_sel_filters}
5959

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'):
6562
new_filter_name = '0_ShaftOpenings'
66-
67-
# Create new if doesn't exist
6863
if new_filter_name not in dict_sel_filters:
6964
new_fil = SelectionFilterElement.Create(doc, new_filter_name)
7065
new_fil.AddSet(element_ids)
7166
print ('Created a filter called : {}'.format(new_filter_name))
72-
73-
# Update if already exists
7467
else:
7568
existing_fil = dict_sel_filters[new_filter_name]
7669
existing_fil.AddSet(element_ids)
7770
print ('Updated a filter called : {}'.format(new_filter_name))
7871

79-
t.Commit()
80-
except Exception as ex:
81-
if t.HasStarted():
82-
t.RollBack()
83-
script.exit(str(ex))
84-
8572
# Report
86-
8773
output.print_md("#### There are {} openings (floor, wall, shaft, roof) in the project.".format(len(all_elements))) # TO DO Output link for all.
8874
if data:
8975
output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])

0 commit comments

Comments
 (0)