I have a script made by another user before leaving the team who was trying to create a parameter linker where if parameter A changes, B changes. I don’t think it was ever finished. I try to run it and get this message
but when i make a change to the comments, i’ll get this other message
the code itself is a bit hard for me to understand yet.
at one point i got a few messages when i restarted revit about
what could cause this?
this is what was started:
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference('System')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.Attributes import *
from System import Guid
from System.Collections.Generic import List
# Custom Updater class
class ParameterLinkerUpdater(IUpdater):
def __init__(self, addin_id, source_param_name, target_param_name):
self.addin_id = addin_id
self.updater_id = UpdaterId(self.addin_id, Guid.NewGuid())
self.source_param_name = source_param_name
self.target_param_name = target_param_name
def GetUpdaterId(self):
return self.updater_id
def GetUpdaterName(self):
return "Parameter Linker Updater"
def GetAdditionalInformation(self):
return "Updates linked parameters dynamically"
def GetChangePriority(self):
return ChangePriority.MEPSystems # Using a valid priority
def Execute(self, data):
doc = data.GetDocument()
for id in data.GetModifiedElementIds():
element = doc.GetElement(id)
source_param = element.LookupParameter(self.source_param_name)
target_param = element.LookupParameter(self.target_param_name)
if source_param and target_param:
# Transfer the value from the source parameter to the target parameter
target_param.Set(source_param.AsString())
TaskDialog.Show("Parameter Linker", "Updated {} based on {}".format(self.target_param_name, self.source_param_name))
# Function to register the updater
def register_updater(doc, source_param_name, target_param_name):
app = doc.Application
addin_id = app.ActiveAddInId
updater = ParameterLinkerUpdater(addin_id, source_param_name, target_param_name)
# Register the updater with Revit
UpdaterRegistry.RegisterUpdater(updater)
# Define filter criteria to track all elements with the specified source parameter
param_id = ElementId(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) # Use a valid parameter ID
filter = ElementParameterFilter(ParameterFilterRuleFactory.CreateContainsRule(param_id, "", True))
# Register triggers (parameter changes) that will activate the updater
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeParameter(param_id))
return updater
# Function to unregister the updater (optional)
def unregister_updater(updater):
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId())
# Main function to create and register parameter links
def main():
doc = __revit__.ActiveUIDocument.Document
# Define the source and target parameter names
source_param_name = "Comments"
target_param_name = "Mark"
# Register the updater
updater = register_updater(doc, source_param_name, target_param_name)
TaskDialog.Show("Parameter Linker", "Parameter Linker Updater registered to update '{}' whenever '{}' changes.".format(target_param_name, source_param_name))
main()