Using Dynamic Model Updater (DMU), we can track any changes of the value of a custom project parameter. There might be various approaches to meet this requirement and one such approach is mentioned in this blog.
This approach assumes that the Project Parameter and the Category it is bound to is known. Even if only the name of the Project Parameter is known, the ParameterBindings list can be used to extract the Category that any given Project Parameter is bound to. The ParameterBindings SDK sample shows how we can access this list.
In the following approach, the DMU is registered at Document level and if there is no element in the current model of the category to which the Project Parameter is bound, or if the model does not contain the Project Parameter itself, the code does not register the Updater itself. Since the goal of this requirement is to track any changes to the value of the Project Parameter, it is assumed that the code will be relevant only when there is atleast one element which belongs to the same category as the Project Parameter is bound to and also has the Project Parameter listed as one of its parameters (in cases where the model might have the element but the model does not have the Project Parameter itself).
For simplicity in the following sample, it is being assumed that we know the name of the Project Parameter to be “Adsk” and that it is bound to instances of Door category.
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
// Assuming the Project Parameter and the Category that it
// is associated with is known.
// For simplicity, this sample assumes that the project parameter
// is called Adsk and it is bound to Door category.
// Since the intention is to track the change of value of
// Project Parameters, it is being assumed that an instance
// which uses the project parameter already exists in the model.
// If it does not exist, the DMU will not be registered
FilteredElementCollector coll = new FilteredElementCollector(doc);
coll
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_Doors);
Element ele = coll.ToElements().First() as Element;
FamilyInstance door = ele as FamilyInstance;
if (null != door)
{
if (null != door.get_Parameter("Adsk"))
{
DoorParamUpdater doorUpdater =
new DoorParamUpdater(uiApp.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(doorUpdater);
ElementClassFilter instanceFilter =
new ElementClassFilter(typeof(FamilyInstance));
UpdaterRegistry.AddTrigger(
doorUpdater.GetUpdaterId(),
instanceFilter,
Element.GetChangeTypeParameter(
door.get_Parameter("Adsk")));
}
}
return Result.Succeeded;
}
}
public class DoorParamUpdater : IUpdater
{
UpdaterId m_updaterId = null;
public void Execute(UpdaterData data)
{
TaskDialog.Show("Change", "You changed something!");
}
public string GetAdditionalInformation()
{
return "This updater checks for changes in Project Param value";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.DoorsOpeningsWindows;
}
public UpdaterId GetUpdaterId()
{
return m_updaterId;
}
public string GetUpdaterName()
{
return "ProjectParameter Updater";
}
public DoorParamUpdater(AddInId id)
{
m_updaterId =
new UpdaterId(id, new Guid("EF43510F-38CB-4980-844C-72174A674D56"));
}
}
}