Skip to content

Commit 3c40401

Browse files
author
EF
committed
Added "Get Openings" tool to analyze panel
1 parent e812ffd commit 3c40401

File tree

2 files changed

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

2 files changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
- to do
18+
_____________________________________________________________________
19+
REQUIREMENTS:
20+
_____________________________________________________________________
21+
[24.03.2024] - Added selection Filter
22+
[23.03.2024] - 1.0 First Release"""
23+
24+
# Imports
25+
26+
from Autodesk.Revit.UI.Selection import *
27+
from Autodesk.Revit.DB import *
28+
import os, sys, math, datetime, time
29+
from Autodesk.Revit.DB import *
30+
31+
# pyRevit
32+
from pyrevit import *
33+
from pyrevit import script
34+
35+
# .NET Imports
36+
import clr
37+
clr.AddReference('System')
38+
from System.Collections.Generic import List
39+
import time
40+
41+
doc =__revit__.ActiveUIDocument.Document
42+
uidoc =__revit__.ActiveUIDocument
43+
output = script.get_output()
44+
selection = uidoc.Selection
45+
timer_start = time.time()
46+
47+
# GET ALL OPENINGS IN THE PROJECT
48+
49+
# 1. List of categories
50+
cats = [BuiltInCategory.OST_FloorOpening,
51+
BuiltInCategory.OST_SWallRectOpening,
52+
BuiltInCategory.OST_ShaftOpening,
53+
BuiltInCategory.OST_RoofOpening]
54+
list_cats = List[BuiltInCategory](cats)
55+
56+
# 2. Create filter
57+
multi_cat_filter = ElementMulticategoryFilter(list_cats)
58+
59+
# 3. Apply filter to filteredElementCollector
60+
all_elements = FilteredElementCollector(doc)\
61+
.WherePasses(multi_cat_filter)\
62+
.WhereElementIsNotElementType()\
63+
.ToElements()
64+
65+
# Get elements for selection filter
66+
element_ids = FilteredElementCollector(doc).OfClass(Opening).ToElementIds()
67+
element_ids = List[ElementId](element_ids)
68+
69+
# 4. Declaration of a list to contains list of wanted element properties
70+
data = []
71+
72+
# 5. Collect information about the object and put it into in the data list.
73+
for e in all_elements:
74+
el = []
75+
el.append(e.Name)
76+
el.append(e.Id)
77+
# add IFC Classification if parameter exist
78+
e_link = output.linkify(e.Id)
79+
el.append(e_link)
80+
data.append(el)
81+
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+
88+
# Get All Selection Filters
89+
all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
90+
dict_sel_filters = {f.Name: f for f in all_sel_filters}
91+
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+
112+
# ╦═╗╔═╗╔═╗╔═╗╦═╗╔╦╗╔═╗
113+
# ╠╦╝║╣ ╠═╝║ ║╠╦╝ ║ ╚═╗
114+
# ╩╚═╚═╝╩ ╚═╝╩╚═ ╩ ╚═╝
115+
#==================================================
116+
117+
output.print_md("#### There are {} shaftopenings in the project.".format(len(all_elements))) # TO DO Output link for all.
118+
if data:
119+
output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])
120+
#output.print_md("#####Total {} WDB/WA elements has been updated.".format(len(data)))
121+
else:
122+
output.print_md("#####There are no shaft openings in the project")
123+
124+
# End
125+
output.print_md('---')
126+
output.print_md('#### Script has finished in {}s'.format(time.time() - timer_start))

0 commit comments

Comments
 (0)