Skip to content

Commit abad8a0

Browse files
author
EF
committed
Added "Get Openings" tool to analyze panel
1 parent 30fc6f1 commit abad8a0

File tree

2 files changed

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

2 files changed

+131
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# -*- coding: utf-8 -*-
2+
3+
__title__ = "Get Openings"
4+
__author__ = "Jakob Steiner"
5+
__doc__ = """Version = 1.1
6+
Date = 24.03.2024
7+
_____________________________________________________________________
8+
Scans trough the project for openings. A list with clickable
9+
links will be presented. Open a 3D view to acces and see the
10+
selected openings. A selection Filter will be created or
11+
update to select all openings with one click.
12+
13+
Inspired by the initial work of Mohamed Bedair and Andreas Draxl.
14+
Special thanks to Erik Frits for his help.
15+
_____________________________________________________________________
16+
TO DO:
17+
- Create a temporary representation wrapper (group containing
18+
directshape object and opening). Create a new 3D View with
19+
these groups and erase direct shapes afterwoods.
20+
- Create a button in output window to call the select filter
21+
and close the output window.
22+
- Integrate IFC classification if present in project.
23+
_____________________________________________________________________
24+
REQUIREMENTS:
25+
_____________________________________________________________________
26+
[24.03.2024] - Added selection Filter
27+
[23.03.2024] - 1.0 First Release"""
28+
29+
# Imports
30+
31+
from Autodesk.Revit.UI.Selection import *
32+
from Autodesk.Revit.DB import *
33+
import os, sys, math, datetime, time
34+
from Autodesk.Revit.DB import *
35+
36+
# pyRevit
37+
from pyrevit import *
38+
from pyrevit import script
39+
40+
# .NET Imports
41+
import clr
42+
clr.AddReference('System')
43+
from System.Collections.Generic import List
44+
import time
45+
46+
doc =__revit__.ActiveUIDocument.Document
47+
uidoc =__revit__.ActiveUIDocument
48+
output = script.get_output()
49+
selection = uidoc.Selection
50+
timer_start = time.time()
51+
52+
# GET ALL OPENINGS IN THE PROJECT
53+
54+
# 1. List of categories
55+
cats = [BuiltInCategory.OST_FloorOpening,
56+
BuiltInCategory.OST_SWallRectOpening,
57+
BuiltInCategory.OST_ShaftOpening,
58+
BuiltInCategory.OST_RoofOpening]
59+
list_cats = List[BuiltInCategory](cats)
60+
61+
# 2. Create filter
62+
multi_cat_filter = ElementMulticategoryFilter(list_cats)
63+
64+
# 3. Apply filter to filteredElementCollector
65+
all_elements = FilteredElementCollector(doc)\
66+
.WherePasses(multi_cat_filter)\
67+
.WhereElementIsNotElementType()\
68+
.ToElements()
69+
70+
# Get elements for selection filter
71+
element_ids = FilteredElementCollector(doc).OfClass(Opening).ToElementIds()
72+
element_ids = List[ElementId](element_ids)
73+
74+
# 4. Declaration of a list to contains list of wanted element properties
75+
data = []
76+
77+
# 5. Collect information about the object and put it into in the data list.
78+
for e in all_elements:
79+
el = []
80+
el.append(e.Name)
81+
el.append(e.Id)
82+
# add IFC Classification if parameter exist
83+
e_link = output.linkify(e.Id)
84+
el.append(e_link)
85+
data.append(el)
86+
87+
# # Get names of current selection filters in doc an print them
88+
# namedFilters = FilteredElementCollector(doc).OfClass(FilterElement).ToElements()
89+
# for nF in namedFilters:
90+
# print (nF.Name) # print names
91+
# print (nF.Id) # print Id
92+
93+
# Get All Selection Filters
94+
all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
95+
dict_sel_filters = {f.Name: f for f in all_sel_filters}
96+
97+
t = Transaction(doc, 'Create Openings Filter')
98+
t.Start()
99+
100+
# Selection Filter Name
101+
new_filter_name = '0_ShaftOpenings'
102+
103+
# Create new if doesn't exist
104+
if new_filter_name not in dict_sel_filters:
105+
new_fil = SelectionFilterElement.Create(doc, new_filter_name)
106+
new_fil.AddSet(element_ids)
107+
print ('Created a filter called : {}'.format(new_filter_name))
108+
109+
# Update if already exists
110+
else:
111+
existing_fil = dict_sel_filters[new_filter_name]
112+
existing_fil.AddSet(element_ids)
113+
print ('Updated a filter called : {}'.format(new_filter_name))
114+
115+
t.Commit()
116+
117+
# ╦═╗╔═╗╔═╗╔═╗╦═╗╔╦╗╔═╗
118+
# ╠╦╝║╣ ╠═╝║ ║╠╦╝ ║ ╚═╗
119+
# ╩╚═╚═╝╩ ╚═╝╩╚═ ╩ ╚═╝
120+
#==================================================
121+
122+
output.print_md("#### There are {} shaftopenings in the project.".format(len(all_elements))) # TO DO Output link for all.
123+
if data:
124+
output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])
125+
#output.print_md("#####Total {} WDB/WA elements has been updated.".format(len(data)))
126+
else:
127+
output.print_md("#####There are no shaft openings in the project")
128+
129+
# End
130+
output.print_md('---')
131+
output.print_md('#### Script has finished in {}s'.format(time.time() - timer_start))

0 commit comments

Comments
 (0)