IUpdater for duct system and fill in parameter
Hello forum
I am stuck with the IUpdater, the problem I am facing is that I do not know how to add my trigger.
If the parameter (Duct System Abbreviation) as showed in the screenshot changes on any object (element) I would like to trigger the IUpdater and fill in another parameter which I created.
OnStartUp:
public Result OnStartup(UIControlledApplication application)
{
DuctSystemUpdater updater = new DuctSystemUpdater(application.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(updater);
ElementClassFilter systemFilter = new ElementClassFilter(typeof(MEPSystem));
// Add trigger, if duct system parameter is filled in. Trigger.
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(),
systemFilter,
Element.GetChangeTypeAny());
This is how I am doing this right now, this should check everything in MEPSystem. So the ducts 🙂
OnShutDown:
public Result OnShutdown(UIControlledApplication application)
{
DuctSystemUpdater updater = new DuctSystemUpdater(application.ActiveAddInId);
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
return Result.Succeeded;
}
As for the updater itself:
public class DuctSystemUpdater : IUpdater
{
public static bool m_updateActive = false;
private AddInId addinID = null;
private UpdaterId updaterID = null;
public DuctSystemUpdater(AddInId id)
{
addinID = id;
updaterID = new UpdaterId(addinID, new Guid("5C58B001-B9BD-4E56-8770-858A905F29D0"));
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
ElementClassFilter systemFilter = new ElementClassFilter(typeof(MEPSystem));
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctSystem);
LogicalAndFilter ductSystemFilter = new LogicalAndFilter(systemFilter, filter);
// Apply the filter to the elements in the active document
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> systems = collector.WherePasses(ductSystemFilter).ToElements();
foreach (MEPSystem ms in systems)
{
foreach (Element element in ms.Elements)
{
// Add new parameter to each element
// Add 4 options through a case
Parameter paraValue = element.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM);
string sParameter = paraValue.ToString();
Parameter p = element.LookupParameter("AE calc");
p.AsValueString();
switch (sParameter)
{
// W5700_Luchtbehandeling, retour // M570R
case "M570R":
p.Set(1);
break;
// W5700_Luchtbehandeling, toevoer // M570F
case "M570F":
p.Set(2);
break;
// W5700_Luchtbehandeling, uitblaaslucht buiten // M570E
case "M570E":
p.Set(3);
break;
// W5700_Luchtbehandeling, aanzuiglucht buiten // M570A
case "M570A":
p.Set(4);
break;
// Breaking out of the case if parameter is not like cases above.
default:
Console.WriteLine("Case does not match.");
break;
}
}
}
}
// Copy pasta from the internet, else it gives exceptions
public string GetAdditionalInformation()
{
return "N/A";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.FreeStandingComponents;
}
public UpdaterId GetUpdaterId()
{
return updaterID;
}
public string GetUpdaterName()
{
return "ParameterUpdater";
}
}
I am not getting this to work, does anybody also know how you can view the trigger in the code if it works or not? If somebody can help me with parameters or code on how to actually debug or follow a along as this runs because I do not know to follow the code. Or force the executer.
Thanks in advance
Greetings
Sebastiaan