From 567b20f201d01f8ed7db72baa79ae3af4913d768 Mon Sep 17 00:00:00 2001 From: Jonathon Broughton Date: Fri, 27 Oct 2023 01:24:51 +0100 Subject: [PATCH] Correct Parameter Name Key --- Rules/actions.py | 4 +++- main.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Rules/actions.py b/Rules/actions.py index af6a73c..ce2c4df 100644 --- a/Rules/actions.py +++ b/Rules/actions.py @@ -64,7 +64,9 @@ def apply(self, parameter: Union[Base, Dict[str, Any]], parent_object: Base) -> if param_name.startswith(self.forbidden_prefix): # If the parameter's name starts with the forbidden prefix, remove it if isinstance(parent_object['parameters'], Base): - parent_object['parameters'].__dict__.pop(param_name) + # double-check the parent object's parameters contain the parameter by applicationInternalName + if parameter.get("applicationInternalName") in parent_object['parameters'].__dict__: + parent_object['parameters'].__dict__.pop(parameter["applicationInternalName"]) # Record this removal in our affected_parameters dictionary self.affected_parameters[parent_object['id']].append(param_name) diff --git a/main.py b/main.py index 52d92f2..7c28849 100644 --- a/main.py +++ b/main.py @@ -64,6 +64,8 @@ def automate_function( # Actions removal_action = PrefixRemovalAction(function_inputs.forbidden_parameter_prefix) + cleansed_objects = set() + # Iterate over each context in the traversal contexts collection. # Each context represents an object (or a nested part of an object) within # the data structure that was traversed. @@ -82,11 +84,29 @@ def automate_function( if is_revit_parameter(parameter) and has_forbidden_prefix(parameter): removal_action.apply(parameter, current_object) + if current_object.id not in cleansed_objects: + cleansed_objects.add(current_object.id) + + # check the affected objects of all actions and count them + affected_objects = set() + for action in [removal_action]: + affected_objects.update(action.affected_parameters) + + if not affected_objects or len(affected_objects) == 0: + automate_context.mark_run_success("No parameters were removed.") + return # Generate reports for all actions. for action in [removal_action]: action.report(automate_context) + new_version_id = automate_context.create_new_version_in_project(version_root_object, "cleansed", + "Cleansed Parameters") + + if not new_version_id: + automate_context.mark_run_failed("Failed to create a new version.") + return + # Final summary. automate_context.mark_run_success("Actions applied and reports generated.")