|
13 | 13 | Inspired by the initial work of Mohamed Bedair and Andreas Draxl.
|
14 | 14 | Special thanks to Erik Frits for his help.
|
15 | 15 | _____________________________________________________________________
|
16 |
| -TO DO: |
17 |
| -- to do |
18 |
| -_____________________________________________________________________ |
19 | 16 | REQUIREMENTS:
|
20 | 17 | _____________________________________________________________________
|
21 | 18 | [24.03.2024] - Added selection Filter
|
22 | 19 | [23.03.2024] - 1.0 First Release"""
|
23 | 20 |
|
24 |
| -# Imports |
| 21 | +# IMPORTS |
| 22 | + |
| 23 | +# .NET |
| 24 | +import clr |
| 25 | +clr.AddReference('System') |
| 26 | +from System.Collections.Generic import List |
| 27 | +import time |
25 | 28 |
|
| 29 | +# Revit |
26 | 30 | from Autodesk.Revit.UI.Selection import *
|
27 | 31 | from Autodesk.Revit.DB import *
|
28 |
| -import os, sys, math, datetime, time |
29 |
| -from Autodesk.Revit.DB import * |
30 | 32 |
|
31 | 33 | # pyRevit
|
32 | 34 | from pyrevit import *
|
33 | 35 | from pyrevit import script
|
34 | 36 |
|
35 |
| -# .NET Imports |
36 |
| -import clr |
37 |
| -clr.AddReference('System') |
38 |
| -from System.Collections.Generic import List |
39 |
| -import time |
40 |
| - |
41 | 37 | doc =__revit__.ActiveUIDocument.Document
|
42 | 38 | uidoc =__revit__.ActiveUIDocument
|
43 | 39 | output = script.get_output()
|
|
46 | 42 |
|
47 | 43 | # GET ALL OPENINGS IN THE PROJECT
|
48 | 44 |
|
49 |
| -# 1. List of categories |
| 45 | +# List of categories |
50 | 46 | cats = [BuiltInCategory.OST_FloorOpening,
|
51 | 47 | BuiltInCategory.OST_SWallRectOpening,
|
52 | 48 | BuiltInCategory.OST_ShaftOpening,
|
53 | 49 | BuiltInCategory.OST_RoofOpening]
|
54 | 50 | list_cats = List[BuiltInCategory](cats)
|
55 | 51 |
|
56 |
| -# 2. Create filter |
| 52 | +# Create filter |
57 | 53 | multi_cat_filter = ElementMulticategoryFilter(list_cats)
|
58 | 54 |
|
59 |
| -# 3. Apply filter to filteredElementCollector |
| 55 | +# Apply filter to filteredElementCollector |
60 | 56 | all_elements = FilteredElementCollector(doc)\
|
61 | 57 | .WherePasses(multi_cat_filter)\
|
62 | 58 | .WhereElementIsNotElementType()\
|
|
66 | 62 | element_ids = FilteredElementCollector(doc).OfClass(Opening).ToElementIds()
|
67 | 63 | element_ids = List[ElementId](element_ids)
|
68 | 64 |
|
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 |
70 | 66 | data = []
|
71 | 67 |
|
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. |
73 | 69 | for e in all_elements:
|
74 | 70 | el = []
|
75 | 71 | el.append(e.Name)
|
|
79 | 75 | el.append(e_link)
|
80 | 76 | data.append(el)
|
81 | 77 |
|
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 | 78 | # Get All Selection Filters
|
89 | 79 | all_sel_filters = FilteredElementCollector(doc).OfClass(SelectionFilterElement).ToElements()
|
90 | 80 | dict_sel_filters = {f.Name: f for f in all_sel_filters}
|
91 | 81 |
|
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)) |
112 | 106 | # ╦═╗╔═╗╔═╗╔═╗╦═╗╔╦╗╔═╗
|
113 | 107 | # ╠╦╝║╣ ╠═╝║ ║╠╦╝ ║ ╚═╗
|
114 | 108 | # ╩╚═╚═╝╩ ╚═╝╩╚═ ╩ ╚═╝
|
115 | 109 | #==================================================
|
116 | 110 |
|
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. |
118 | 112 | if data:
|
119 | 113 | output.print_table(table_data=data, title="Shafts:", columns=["Family" ,"ElementId", "Select/Show Element"])
|
120 | 114 | #output.print_md("#####Total {} WDB/WA elements has been updated.".format(len(data)))
|
121 | 115 | 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") |
123 | 117 |
|
124 | 118 | # End
|
125 | 119 | output.print_md('---')
|
|
0 commit comments