I have the following code below. It allows the user to select a first element’s selected parameter (example: comment) and push it to a second element’s selected parameter (example: mark).
the code works as I expect it to, however, after it has been executed, Revit will show the blue spinning circle like it’s still thinking or something. it goes on and off every few seconds. I hit escape but it still happens.
Any suggestions on what might be causing this?
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
from pyrevit import revit, forms
# Function to get parameter names from an element
def get_parameter_names(element):
parameter_names = []
parameters = element.Parameters
for parameter in parameters:
parameter_names.append(parameter.Definition.Name)
return sorted(parameter_names) # Sort the parameter names alphabetically
# Function to select an element
def select_element(prompt):
uidoc = __revit__.ActiveUIDocument
reference = uidoc.Selection.PickObject(ObjectType.Element, prompt)
return uidoc.Document.GetElement(reference.ElementId)
# Get the active UIDocument
uidoc = __revit__.ActiveUIDocument
# Prompt user to select the first element
first_selected_element = select_element("Select the first element")
if first_selected_element:
# Get parameter names from the first selected element
parameter_names_first = get_parameter_names(first_selected_element)
# Allow the user to select a parameter from the dropdown list for the first element
selected_parameter_name_first = forms.SelectFromList.show(parameter_names_first,
title="Select Parameter for the first element",
multiselect=False)
if selected_parameter_name_first:
# Get the parameter object for the selected parameter for the first element
parameter_first = first_selected_element.LookupParameter(selected_parameter_name_first)
if parameter_first:
# Get the parameter value of the first element
parameter_value_first = parameter_first.AsString()
# Prompt user to select the second element
second_selected_element = select_element("Select the second element")
if second_selected_element:
# Get parameter names from the second selected element
parameter_names_second = get_parameter_names(second_selected_element)
# Allow the user to select a parameter from the dropdown list for the second element
selected_parameter_name_second = forms.SelectFromList.show(parameter_names_second,
title="Select Parameter for the second element",
multiselect=False)
if selected_parameter_name_second:
# Get the parameter object for the selected parameter for the second element
parameter_second = second_selected_element.LookupParameter(selected_parameter_name_second)
if parameter_second:
# Set the parameter value of the second element to be the same as the first element
t = Transaction(uidoc.Document, "Replace Parameter Value")
t.Start()
parameter_second.Set(parameter_value_first)
t.Commit()
print("Parameter value of the second element replaced with the value of the first element.")
else:
print("Parameter not found for the second element.")
else:
print("No parameter selected for the second element.")
else:
print("No second element selected.")
else:
print("Parameter not found for the first element.")
else:
print("No parameter selected for the first element.")
else:
print("No first element selected.")