Skip to content

Commit a2b4fa5

Browse files
author
EF
committed
Corrected @devloai[bot] suggestions
1 parent 3c40401 commit a2b4fa5

File tree

1 file changed

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

1 file changed

+39
-45
lines changed

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

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,27 @@
1313
Inspired by the initial work of Mohamed Bedair and Andreas Draxl.
1414
Special thanks to Erik Frits for his help.
1515
_____________________________________________________________________
16-
TO DO:
17-
- to do
18-
_____________________________________________________________________
1916
REQUIREMENTS:
2017
_____________________________________________________________________
2118
[24.03.2024] - Added selection Filter
2219
[23.03.2024] - 1.0 First Release"""
2320

24-
# Imports
21+
# IMPORTS
22+
23+
# .NET
24+
import clr
25+
clr.AddReference('System')
26+
from System.Collections.Generic import List
27+
import time
2528

29+
# Revit
2630
from Autodesk.Revit.UI.Selection import *
2731
from Autodesk.Revit.DB import *
28-
import os, sys, math, datetime, time
29-
from Autodesk.Revit.DB import *
3032

3133
# pyRevit
3234
from pyrevit import *
3335
from pyrevit import script
3436

35-
# .NET Imports
36-
import clr
37-
clr.AddReference('System')
38-
from System.Collections.Generic import List
39-
import time
40-
4137
doc =__revit__.ActiveUIDocument.Document
4238
uidoc =__revit__.ActiveUIDocument
4339
output = script.get_output()
@@ -46,17 +42,17 @@
4642

4743
# GET ALL OPENINGS IN THE PROJECT
4844

49-
# 1. List of categories
45+
# List of categories
5046
cats = [BuiltInCategory.OST_FloorOpening,
5147
BuiltInCategory.OST_SWallRectOpening,
5248
BuiltInCategory.OST_ShaftOpening,
5349
BuiltInCategory.OST_RoofOpening]
5450
list_cats = List[BuiltInCategory](cats)
5551

56-
# 2. Create filter
52+
# Create filter
5753
multi_cat_filter = ElementMulticategoryFilter(list_cats)
5854

59-
# 3. Apply filter to filteredElementCollector
55+
# Apply filter to filteredElementCollector
6056
all_elements = FilteredElementCollector(doc)\
6157
.WherePasses(multi_cat_filter)\
6258
.WhereElementIsNotElementType()\
@@ -66,10 +62,10 @@
6662
element_ids = FilteredElementCollector(doc).OfClass(Opening).ToElementIds()
6763
element_ids = List[ElementId](element_ids)
6864

69-
# 4. Declaration of a list to contains list of wanted element properties
65+
# Declaration of a list to contains list of wanted element properties
7066
data = []
7167

72-
# 5. Collect information about the object and put it into in the data list.
68+
# Collect information about the object and put it into in the data list.
7369
for e in all_elements:
7470
el = []
7571
el.append(e.Name)
@@ -79,47 +75,45 @@
7975
el.append(e_link)
8076
data.append(el)
8177

82-
# # Get names of current selection filters in doc an print them
83-
# namedFilters = FilteredElementCollector(doc).OfClass(FilterElement).ToElements()
84-
# for nF in namedFilters:
85-
# print (nF.Name) # print names
86-
# print (nF.Id) # print Id
87-
8878
# Get All Selection Filters
8979
all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
9080
dict_sel_filters = {f.Name: f for f in all_sel_filters}
9181

92-
t = Transaction(doc, 'Create Openings Filter')
93-
t.Start()
94-
95-
# Selection Filter Name
96-
new_filter_name = '0_ShaftOpenings'
97-
98-
# Create new if doesn't exist
99-
if new_filter_name not in dict_sel_filters:
100-
new_fil = SelectionFilterElement.Create(doc, new_filter_name)
101-
new_fil.AddSet(element_ids)
102-
print ('Created a filter called : {}'.format(new_filter_name))
103-
104-
# Update if already exists
105-
else:
106-
existing_fil = dict_sel_filters[new_filter_name]
107-
existing_fil.AddSet(element_ids)
108-
print ('Updated a filter called : {}'.format(new_filter_name))
109-
110-
t.Commit()
111-
82+
try:
83+
t = Transaction(doc, 'Create Openings Filter')
84+
t.Start()
85+
86+
# Selection Filter Name
87+
new_filter_name = '0_ShaftOpenings'
88+
89+
# Create new if doesn't exist
90+
if new_filter_name not in dict_sel_filters:
91+
new_fil = SelectionFilterElement.Create(doc, new_filter_name)
92+
new_fil.AddSet(element_ids)
93+
print ('Created a filter called : {}'.format(new_filter_name))
94+
95+
# Update if already exists
96+
else:
97+
existing_fil = dict_sel_filters[new_filter_name]
98+
existing_fil.AddSet(element_ids)
99+
print ('Updated a filter called : {}'.format(new_filter_name))
100+
101+
t.Commit()
102+
except Exception as ex:
103+
if t.HasStarted():
104+
t.RollBack()
105+
script.exit(str(ex))
112106
# ╦═╗╔═╗╔═╗╔═╗╦═╗╔╦╗╔═╗
113107
# ╠╦╝║╣ ╠═╝║ ║╠╦╝ ║ ╚═╗
114108
# ╩╚═╚═╝╩ ╚═╝╩╚═ ╩ ╚═╝
115109
#==================================================
116110

117-
output.print_md("#### There are {} shaftopenings in the project.".format(len(all_elements))) # TO DO Output link for all.
111+
output.print_md("#### There are {} openings (floor, wall, shaft, roof) in the project.".format(len(all_elements))) # TO DO Output link for all.
118112
if data:
119113
output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])
120114
#output.print_md("#####Total {} WDB/WA elements has been updated.".format(len(data)))
121115
else:
122-
output.print_md("#####There are no shaft openings in the project")
116+
output.print_md("#####There are no openings (floor, wall, shaft, roof) in the project")
123117

124118
# End
125119
output.print_md('---')

0 commit comments

Comments
 (0)