Namespace:
Autodesk.Revit.DB
IUpdater
Interface
Description:
The interface used to create an updater capable of reacting to changes in the Revit model.
The interface used to create an updater capable of reacting to changes in the Revit model.
Remarks:
Implement this interface and register an instance of the derived class with the UpdaterRegistry.
Implement this interface and register an instance of the derived class with the UpdaterRegistry.
Examples
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";
}
}
IUpdater Interface Members:
Name | Description |
---|---|
Execute | The method that Revit will invoke to perform an update. |
GetAdditionalInformation | Auxiliary text that Revit will use to inform the end user when the Updater is not loaded |
GetChangePriority | 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 |
GetUpdaterId | Returns globally unique updater id - used to identify the Updater Called once during registration of the updater |
GetUpdaterName | Returns a name that the Updater can be identified by to the user |