-
-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathscript.py
More file actions
64 lines (51 loc) · 1.85 KB
/
Copy pathscript.py
File metadata and controls
64 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
from pyrevit import forms, revit, script, DB
from pyrevit.revit import query
logger = script.get_logger()
def get_views_with_sfm():
"""Map each view that has an active SpatialFieldManager to that manager."""
v_sfm_dict = {}
for v in query.get_all_views():
try:
if not v.AllowsAnalysisDisplay():
continue
sfm = DB.Analysis.SpatialFieldManager.GetSpatialFieldManager(v)
if sfm is None:
continue
v_sfm_dict[v] = sfm
except Exception as ex:
logger.debug("Skipped view {}: {}".format(getattr(v, "Id", v), ex))
return v_sfm_dict
def main():
"""Let user select which view(s) to purge AVF (SpatialFieldManager) data from."""
v_sfm_dict = get_views_with_sfm()
if not v_sfm_dict:
print("No views with an active Analysis Visualization Framework (AVF) found.")
return
selection = forms.SelectFromList.show(
list(v_sfm_dict.keys()),
name_attr="Name",
multiselect=True,
title="Select Views to Purge AVF",
button_name="Purge Selected Views",
)
if not selection:
print("Nothing selected.")
return
purged = 0
skipped = 0
# Transaction not necessary, added to safeguard in case future Revit versions require it
with revit.Transaction("Purge AVF"):
for v in selection:
sfm = v_sfm_dict.get(v)
try:
sfm.Clear()
purged += 1
print("Purged AVF: {}".format(v.Name))
except Exception as ex:
logger.exception("Failed purging AVF on view {}: {}".format(v.Name, ex))
skipped += 1
revit.uidoc.RefreshActiveView()
print("Done. Purged: " + str(purged) + " | Skipped: " + str(skipped))
if __name__ == "__main__":
main()