1
1
"""Compare instance and type properties between two elements."""
2
- #pylint: disable=import-error,invalid-name,broad-except
2
+ # pylint: disable=import-error,invalid-name,broad-except
3
3
from pyrevit import revit , DB
4
4
from pyrevit import forms
5
5
from pyrevit import script
@@ -51,6 +51,100 @@ def grab_props(src_element):
51
51
if x .Definition .Name not in EXCLUDE_PARAMS ]
52
52
53
53
54
+ def compare_view_filters (view1 , view2 ):
55
+ output .print_md ("### View Filters" )
56
+
57
+ filters1 = set (view1 .GetFilters ())
58
+ filters2 = set (view2 .GetFilters ())
59
+
60
+ filter_names1 = {view1 .Document .GetElement (fid ).Name : fid for fid in filters1 }
61
+ filter_names2 = {view2 .Document .GetElement (fid ).Name : fid for fid in filters2 }
62
+
63
+ shared_filters = set (filter_names1 .keys ()).intersection (set (filter_names2 .keys ()))
64
+ only_in_1 = set (filter_names1 .keys ()) - set (filter_names2 .keys ())
65
+ only_in_2 = set (filter_names2 .keys ()) - set (filter_names1 .keys ())
66
+
67
+ if only_in_1 or only_in_2 :
68
+ rows = [[n , "" ] for n in sorted (only_in_1 )]
69
+ rows .extend ([["" , n ] for n in sorted (only_in_2 )])
70
+ output .print_table (
71
+ rows ,
72
+ columns = ["Only in Source View" , "Only in Target View" ],
73
+ title = "Different Filter Assignments" ,
74
+ )
75
+
76
+ for fname in sorted (shared_filters ):
77
+ fid1 = filter_names1 [fname ]
78
+ fid2 = filter_names2 [fname ]
79
+
80
+ ov1 = view1 .GetFilterOverrides (fid1 )
81
+ ov2 = view2 .GetFilterOverrides (fid2 )
82
+
83
+ differences = []
84
+
85
+ # Compare properties of OverrideGraphicSettings
86
+ ov_attrs = [
87
+ # Colors
88
+ "ProjectionLineColor" ,
89
+ "SurfaceForegroundPatternColor" ,
90
+ "SurfaceBackgroundPatternColor" ,
91
+ "CutLineColor" ,
92
+ "CutForegroundPatternColor" ,
93
+ "CutBackgroundPatternColor" ,
94
+
95
+ # Pattern IDs
96
+ "SurfaceForegroundPatternId" ,
97
+ "SurfaceBackgroundPatternId" ,
98
+ "CutForegroundPatternId" ,
99
+ "CutBackgroundPatternId" ,
100
+ "ProjectionLinePatternId" ,
101
+ "CutLinePatternId" ,
102
+
103
+ # Line weights
104
+ "ProjectionLineWeight" ,
105
+ "CutLineWeight" ,
106
+
107
+ # Visibility flags
108
+ "IsSurfaceForegroundPatternVisible" ,
109
+ "IsSurfaceBackgroundPatternVisible" ,
110
+ "IsCutForegroundPatternVisible" ,
111
+ "IsCutBackgroundPatternVisible" ,
112
+
113
+ # Other
114
+ "Transparency" ,
115
+ "Halftone" ,
116
+ ]
117
+
118
+ for attr in ov_attrs :
119
+ val1 = getattr (ov1 , attr )
120
+ val2 = getattr (ov2 , attr )
121
+
122
+ if isinstance (val1 , DB .Color ):
123
+ if val1 .IsValid and val2 .IsValid :
124
+ if val1 .Red != val2 .Red or val1 .Green != val2 .Green or val1 .Blue != val2 .Blue :
125
+ differences .append (attr )
126
+ elif val1 .IsValid != val2 .IsValid :
127
+ differences .append (attr )
128
+ else :
129
+ if val1 != val2 :
130
+ differences .append (attr )
131
+
132
+ # More general stuff
133
+ if view1 .GetIsFilterEnabled (fid1 ) != view2 .GetIsFilterEnabled (fid2 ):
134
+ differences .append ("Enabled Status" )
135
+
136
+ if view1 .GetFilterVisibility (fid1 ) != view2 .GetFilterVisibility (fid2 ):
137
+ differences .append ("Visibility Status" )
138
+
139
+ if differences :
140
+ output .print_md (
141
+ ":warning: **Filter '{}' has different overrides:** {}"
142
+ .format (fname , ", " .join (differences )))
143
+ else :
144
+ output .print_md (
145
+ ":white_heavy_check_mark: Filter '{}' overrides match." .format (fname ))
146
+
147
+
54
148
def compare_props (src_element , tgt_element ):
55
149
output .print_md ("### Instance Properties" )
56
150
src_type = revit .query .get_type (src_element )
@@ -106,12 +200,20 @@ def compare_props(src_element, tgt_element):
106
200
title = 'Unique Type Properties'
107
201
)
108
202
203
+ # If both are views, compare filters
204
+ if isinstance (src_element , DB .View ) and isinstance (tgt_element , DB .View ):
205
+ compare_view_filters (src_element , tgt_element )
206
+
207
+
109
208
# main
110
209
# try use selected elements
111
210
selected_elements = revit .get_selection ().elements
112
- if len (selected_elements ) == 1 and forms .alert ("Use selected %s?" % ("view"
113
- if isinstance (selected_elements [0 ], DB .View ) else "element" ),
114
- yes = True , no = True ):
211
+ if len (selected_elements ) == 1 and forms .alert (
212
+ "Use selected %s?"
213
+ % ("view" if isinstance (selected_elements [0 ], DB .View ) else "element" ),
214
+ yes = True ,
215
+ no = True ,
216
+ ):
115
217
source_element = selected_elements [0 ]
116
218
target_type = "Views" if isinstance (source_element , DB .View )\
117
219
else "Elements"
@@ -121,24 +223,35 @@ def compare_props(src_element, tgt_element):
121
223
# some are not selectable in graphical views
122
224
target_type = \
123
225
forms .CommandSwitchWindow .show (
124
- ["Elements" , "Views" ],
226
+ ["Elements" , "Views" , "View Templates" ],
125
227
message = "Pick type of targets:" )
126
228
127
229
# determine source element
128
230
if target_type == "Elements" :
129
- with forms .WarningBar (title = "Pick source object :" ):
130
- source_element = revit .pick_element ()
231
+ with forms .WarningBar (title = "Pick source element :" ):
232
+ source_element = revit .pick_element (message = "Pick source element:" )
131
233
elif target_type == "Views" :
132
234
source_element = \
133
235
forms .select_views (title = "Select Source View" , multiple = False )
236
+ elif target_type == "View Templates" :
237
+ source_element = \
238
+ forms .select_viewtemplates (title = "Select Source View Template" , multiple = False )
134
239
135
240
# grab parameters from source element
136
241
if source_element :
137
242
target_element = None
243
+
244
+ def exclude_source (el ):
245
+ return el .Id != source_element .Id
246
+
138
247
if target_type == "Elements" :
139
- target_element = revit .pick_element (message = "Pick target element:" )
248
+ with forms .WarningBar (title = "Pick target object:" ):
249
+ target_element = revit .pick_element (message = "Pick target element:" )
140
250
elif target_type == "Views" :
141
251
target_element = \
142
- forms .select_views (title = "Select Target View" , multiple = False )
252
+ forms .select_views (title = "Select Target View" , multiple = False , filterfunc = exclude_source )
253
+ elif target_type == "View Templates" :
254
+ target_element = \
255
+ forms .select_viewtemplates (title = "Select Target View Template" , multiple = False , filterfunc = exclude_source )
143
256
if target_element :
144
257
compare_props (source_element , target_element )
0 commit comments