Skip to content

Commit

Permalink
Correct Parameter Name Key
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdbroughton committed Oct 27, 2023
1 parent c147b1f commit 567b20f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Rules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.")

Expand Down

0 comments on commit 567b20f

Please sign in to comment.