IUpdater Interface

The interface used to create an updater capable of reacting to changes in the Revit model.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public interface IUpdater

The IUpdater type exposes the following members.

Methods
 NameDescription
Public methodExecute The method that Revit will invoke to perform an update.
Public methodGetAdditionalInformation Auxiliary text that Revit will use to inform the end user when the Updater is not loaded
Public methodGetChangePriority Identifies the nature of the change the Updater will be performing Used to identify order of execution of updaters Called once during registration of the updater
Public methodGetUpdaterId Returns globally unique updater id - used to identify the Updater Called once during registration of the updater
Public methodGetUpdaterName Returns a name that the Updater can be identified by to the user
Top
Remarks
Implement this interface and register an instance of the derived class with the UpdaterRegistry.
Example
public class WallUpdaterApplication : Autodesk.Revit.UI.IExternalApplication
{
    public Result OnStartup(UIControlledApplication application)
    {
        // Register wall updater with Revit
        WallUpdater updater = new WallUpdater(application.ActiveAddInId);
        UpdaterRegistry.RegisterUpdater(updater);

        // Change Scope = any Wall element
        ElementClassFilter wallFilter = new ElementClassFilter(typeof(Wall));

        // Change type = element addition
        UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), wallFilter,
                                    Element.GetChangeTypeElementAddition());
        return Result.Succeeded;
    }

    public Result OnShutdown(UIControlledApplication application)
    {
        WallUpdater updater = new WallUpdater(application.ActiveAddInId);
        UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
        return Result.Succeeded;
    }
}

public class WallUpdater : IUpdater
{
    static AddInId m_appId;
    static UpdaterId m_updaterId;
    WallType m_wallType = null;

    // constructor takes the AddInId for the add-in associated with this updater
    public WallUpdater(AddInId id)
    {
        m_appId = id;
        m_updaterId = new UpdaterId(m_appId, new Guid("FBFBF6B2-4C06-42d4-97C1-D1B4EB593EFF"));
    }

    public void Execute(UpdaterData data)
    {
        Document doc = data.GetDocument();

        // Cache the wall type
        if (m_wallType == null)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.OfClass(typeof(WallType));
            var wallTypes = from element in collector
                            where
                                element.Name == "Exterior - Brick on CMU"
                            select element;
            if (wallTypes.Count<Element>() > 0)
            {
                m_wallType = wallTypes.Cast<WallType>().ElementAt<WallType>(0);
            }
        }

        if (m_wallType != null)
        {
            // Change the wall to the cached wall type.
            foreach (ElementId addedElemId in data.GetAddedElementIds())
            {
                Wall wall = doc.GetElement(addedElemId) as Wall;
                if (wall != null)
                {
                    wall.WallType = m_wallType;
                }
            }
        }
    }

    public string GetAdditionalInformation()
    {
        return "Wall type updater example: updates all newly created walls to a special wall";
    }

    public ChangePriority GetChangePriority()
    {
        return ChangePriority.FloorsRoofsStructuralWalls;
    }

    public UpdaterId GetUpdaterId()
    {
        return m_updaterId;
    }

    public string GetUpdaterName()
    {
        return "Wall Type Updater";
    }
}
See Also