From 427de7c67d5081c24c061469d0764bf8adcd55f6 Mon Sep 17 00:00:00 2001 From: melnikovalex Date: Sun, 10 May 2020 19:47:26 +0200 Subject: [PATCH] Copy Filter Overrides - support active view, fixes --- .../memo.stack/lib/copypastestate/actions.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/lib/copypastestate/actions.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/lib/copypastestate/actions.py index 0da0495d9..1fde076e0 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/lib/copypastestate/actions.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/lib/copypastestate/actions.py @@ -672,6 +672,14 @@ class FilterOverridesAction(basetypes.CopyPasteStateAction): name = 'Filter Overrides' invalid_context_msg = "" + @staticmethod + def get_suitable_views(): + selected_views = revit.get_selection().only_views() + if not selected_views: + selected_views = [revit.active_view] + return [view for view in selected_views + if view.AreGraphicsOverridesAllowed()] + @staticmethod def controlled_by_template(view): if view.ViewTemplateId != DB.ElementId.InvalidElementId: @@ -685,12 +693,12 @@ def controlled_by_template(view): return False def copy(self): - views = revit.get_selection().only_views() + views = FilterOverridesAction.get_suitable_views() if views: view = views[0] view_filters = revit.query.get_view_filters(view) if not view_filters: - raise PyRevitException('Active view has no fitlers applied') + raise PyRevitException('Active/Selected view has no fitlers applied') selected_filters = forms.SelectFromList.show( view_filters, @@ -720,13 +728,14 @@ def paste(self): # to view template or to selected view mode_templates = \ forms.CommandSwitchWindow.show( - ['Active View', 'Select View Templates'], + ['Active/Selected View', 'Select View Templates'], message='Where do you want to paste filters?' ) == 'Select Templates' if mode_templates: views = forms.select_viewtemplates() else: - views = [revit.active_view] + views = FilterOverridesAction.get_suitable_views() + views = [view for view in views if view.Id != source_view.Id] views_controlled_by_template = \ [x for x in views if FilterOverridesAction.controlled_by_template(x)] @@ -736,7 +745,7 @@ def paste(self): ' They will be skipped' ) if not views: - raise PyRevitException('Nothing selected') + raise PyRevitException('No suitable views selected or active') # check if there are views controlled by template with revit.TransactionGroup('Paste Filter Overrides'): @@ -760,4 +769,4 @@ def paste(self): @staticmethod def validate_context(): - return revit.get_selection().is_empty + return bool(FilterOverridesAction.get_suitable_views())