Monitoring parameter changes using DMU mechanism

Monitoring parameter changes using DMU mechanism

846081597
Enthusiast Enthusiast
781 Views
9 Replies
Message 1 of 10

Monitoring parameter changes using DMU mechanism

846081597
Enthusiast
Enthusiast

Hello everyone

I have encountered some problems recently.

I created some family parameters and displayed them in Revit's properties window

using (Transaction trans = new Transaction(doc))
{
trans.Start("Add Parameter");
familyMgr = doc.FamilyManager;
BuiltInParameterGroup paraGroup = BuiltInParameterGroup.PG_TEXT;
ParameterType paraType = ParameterType.Text;
bool isInstance = false;
paramAdded = familyMgr.AddParameter(paraName, paraGroup, paraType, isInstance);

string value = Paras[key];
familyMgr.Set(paramAdded, value);

trans.Commit();
}

Now I want to implement some functions: if someone modifies the parameter value I defined in the properties window, I can quickly capture this operation and obtain the modified value.

I consider using DMU to realize this function, but I have no way to start. Can you give me some ideas.

thank you

0 Likes
Accepted solutions (1)
782 Views
9 Replies
Replies (9)
Message 2 of 10

jeremy_tammik
Alumni
Alumni

Yes, DMU is a viable option. Read about it here:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.31

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 10

846081597
Enthusiast
Enthusiast

 

Hi jeremy,

Thank you for your help. 

When I added a trigger, I encountered two problems

 UpdaterRegistry.AddTrigger(
      updater.GetUpdaterId(), ElementFilter,
      Element.GetChangeTypeParameter(ElementId) );

First, I won't write ElementFilter for all family parameters in the current document.

Second, Element.GetChangeTypeParameter need an ID, but I don't know which family parameter the user will modify. I can't determine which ID it is.

Please help me

Thanks

0 Likes
Message 4 of 10

jeremy_tammik
Alumni
Alumni

You can subscribe to all changes instead of parameter changes only. Try it out with any subset of elements you want first. You can expand it later, once you have it working at all.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 10

846081597
Enthusiast
Enthusiast


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;

}

}

0 Likes
Message 6 of 10

Kennan.Chen
Advocate
Advocate

How about watching the Document.OwnerFamily?

0 Likes
Message 7 of 10

846081597
Enthusiast
Enthusiast

Hello Kennan.Chen

Sorry, I'm a novice in secondary development. I don't know how to use Document.OwnerFamily.

I mainly want to capture the user's modification of family parameters. I defined several family parameters with the revit api interface. If the user can modify the family parameters I defined, I can capture this operation and obtain the modified values.

When I modified the family parameters, I found that the program did not enter the execute function of ParameterUpdate at all.

ParameterUpdater.AddTrigger(m_updaterId,doc, List<ElementId>,Element.GetChangeTypeAny())

0 Likes
Message 8 of 10

Kennan.Chen
Advocate
Advocate

In your code, you collected all the FamilyParameter ids and ask the DMU to watch modifications on them, which actually didn't work.

Maybe you can give DMU the id of Document.OwnerFamily. I have no idea if it will work. You can have a try.

0 Likes
Message 9 of 10

846081597
Enthusiast
Enthusiast

Hello Kennan.Chen

Thank you for your help. I've tried and still can't. now I doubt whether DMU can't be used for family parameters at all,I really can't find anything wrong.

0 Likes
Message 10 of 10

846081597
Enthusiast
Enthusiast
Accepted solution

I tried to use controlledapplication_ Documentchanged has succeeded. Thank you

0 Likes