The template can be found from the Revit Addin item category:
Accept the default name for the Element Updater or change it to a different one, then the following welcome page will appear:
After the Next button is pressed, the updater options can be set such as class name, updater name, updater description, updater id, change priority, and what kind of operations to monitor:
A default updater id will be created by default and it can be changed to any other valid GUID strings. In the next page, registration options can be set as well:
The wizard also gives a chance to review all the settings:
Now if the Finish button is pressed, a new IUpdater class will be created and registered automatically by RevitAddinWizard.
All relevant code has been appended below for reference:
using System;
using System.Text;
using System.Xml;
using System.Linq;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
namespace RevitAddinCSProject
{
public class ElementUpdater : IUpdater
{
private AddInId mAddinId;
private UpdaterId mUpdaterId;
public ElementUpdater(AddInId id)
{
mAddinId = id;
mUpdaterId = new UpdaterId(mAddinId, new Guid("bf2aa2f6-2fe8-4d0a-ba73-1681c1ff1967"));
}
#region IUpdater Members
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
ICollection<ElementId> addedIds = data.GetAddedElementIds();
foreach (ElementId id in addedIds)
{
Element elem = doc.get_Element(id);
MessageBox.Show(string.Format("{0}({1}) has been added.", elem.Name, id.IntegerValue));
}
ICollection<ElementId> deletedIds = data.GetDeletedElementIds();
foreach (ElementId id in deletedIds)
{
MessageBox.Show(string.Format("{0} has been deleted.", id.IntegerValue));
}
}
public string GetAdditionalInformation()
{
return "ElementUpdater";
}
public ChangePriority GetChangePriority()
{
return Autodesk.Revit.DB.ChangePriority.FloorsRoofsStructuralWalls;
}
public UpdaterId GetUpdaterId()
{
return mUpdaterId;
}
public string GetUpdaterName()
{
return "ElementUpdater";
}
#endregion
}
}
public Result OnStartup(UIControlledApplication uiApp)
{
//…….
// Register the ElementUpdater
ElementUpdater updater1 = new ElementUpdater(uiApp.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(updater1);
ElementCategoryFilter catFilter = new ElementCategoryFilter(Autodesk.Revit.DB.BuiltInCategory.OST_Walls);
UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeElementAddition());
UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeElementDeletion());
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication uiApp)
{
//……
// Unregister the ElementUpdater
UpdaterRegistry.UnregisterUpdater(new ElementUpdater(uiApp.ActiveAddInId).GetUpdaterId());
return Result.Succeeded;
}
Links to some related articles:
Implement IUpdater of Revit API
Implement IFailuresPreprocessor of Revit API
Use RevitAddinWizard to Implement IFailuresPreprocessor of Revit API
Implement An IFailuresProcessor of Revit API
Use RevitAddinWizard to Implement IFailuresProcessor of Revit API
Command Availability And Revit Flavors/Categories of Revit API
Use RevitAddinWizard to Implement IExternalCommandavailability of Revit API
Implement ISelectionFilter of Revit API
Use RevitAddinWizard to Implement ISelectionFilter of Revit API
I seem to be having some problem adding a new Element Updater. It throws an error "Value Cannot be null. Parameter name: type" It's a new VB.NET project.
Posted by: Bwebb | 02/18/2014 at 04:44 PM
Bwebb, may we know which version of Visual Studio?
Posted by: Spiderinnet | 02/18/2014 at 08:22 PM
Bwebb again, please try the latest build #0.9.8.1 which should behave well about it both in Visual Studio 2008 and 2010.
Posted by: Spiderinnet | 02/19/2014 at 10:41 PM