Hello jeremy
Thanks for your help
I wrote a section of parameter trigger based on the information you gave me
However, I did not trigger the parameter trigger after modifying the family parameters in the family document.
Can you help me find the reason。
public class ParameterUpdater : IUpdater
{
internal ParameterUpdater(AddInId addinID)
{
m_updaterId = new UpdaterId(addinID, new Guid("FBF3F6B2-4C06-42d4-97C1-D1B4EB593EFF"));
}
internal void Register(Document doc)
{
if (!UpdaterRegistry.IsUpdaterRegistered(m_updaterId))
UpdaterRegistry.RegisterUpdater(this, doc);
}
internal void AddTriggerForUpdater(Document doc, List<ElementId> idsToWatch)
{
if (idsToWatch.Count == 0)
return;
UpdaterRegistry.AddTrigger(m_updaterId, doc, idsToWatch, Element.GetChangeTypeAny());
}
public void Execute(UpdaterData data)
{
MessageBox.Show("enter change");
return;
}
public UpdaterId GetUpdaterId()
{
return m_updaterId;
}
public string GetUpdaterName()
{
return "Parameter Updater";
}
public string GetAdditionalInformation()
{
return "Automatically add a family parameter";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.Structure;
}
private UpdaterId m_updaterId = null;
}
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Document doc;
public Autodesk.Revit.ApplicationServices.Application app;
private static List<ElementId> idsToWatch = new List<ElementId>();
private static ParameterUpdater m_parameterUpdater = null;
private AddInId m_thisAppId;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
doc = commandData.Application.ActiveUIDocument.Document;
m_thisAppId = commandData.Application.ActiveAddInId;//MessageBox.Show(m_thisAppId.GetGUID().ToString());
if (m_parameterUpdater == null)
{
using (Transaction tran = new Transaction(doc, "Register Section Updater"))
{
tran.Start();
m_parameterUpdater = new ParameterUpdater(m_thisAppId);
m_parameterUpdater.Register(doc);
tran.Commit();
}
}
FamilyParameterSet parameters = doc.FamilyManager.Parameters;
foreach(FamilyParameter para in parameters)
{
idsToWatch.Add(para.Id); //MessageBox.Show(para.Definition.Name);
}
UpdaterRegistry.RemoveAllTriggers(m_parameterUpdater.GetUpdaterId());
m_parameterUpdater.AddTriggerForUpdater(doc, idsToWatch);
doc.DocumentClosing += UnregisterSectionUpdaterOnClose;
return Result.Succeeded;
}
}