We don’t want to discuss how you can modify or set Revit built-in schedule, instead we want to discuss how we can leverage different tools to get most customized schedule. Most of you may suffer when try to customize Revit built-in schedule especially when you want to follow some localization requirements. Revit API doesn’t provide comprehensive access for schedule but it allows 3rd party developer to have almost fully control of elements’ parameters. In addition, Microsoft Excel has powerful customization capability for whatever kinds of schedule you want with plenty help documentation like MSDN. As a result, you have the data and the tool, what obstacle you still?
(For excel help: MSDN-http://msdn.microsoft.com/en-us/library/wss56bz7%28v=vs.80%29.aspx or other documentation)
Here we want to share how you can get up-to-date excel worksheet instead of detail of how you need to write code for excel or get parameters. Revit API provides a wonderful mechanism as IUpdater to let API developer be notified when something is changed inside.
public class ParameterUpdater : IUpdater
{
AddInId addinID;
UpdaterId updaterID;
ElementId paramId;
public ParameterUpdater(AddInId id, BuiltInParameter param)
{
addinID = id;
paramId = new ElementId(param);
updaterID = new UpdaterId(addinID, new Guid(“6BBDEB2B-F83B-40df-9101-01A02DFC1A37″));
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
// update your Excel worksheet…
}
public string GetAdditionalInformation() { return “Element Parameter Changed”; }
public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; }
public UpdaterId GetUpdaterId() { return updaterID; }
public string GetUpdaterName() { return “Element Parameter Changed”; }
public ChangeType GetChangeType() { return Element.GetChangeTypeParameter(paramId); }
}
This class gets Revit model parameter change events through implementing IUpdater interface. All functions are must implemented interfaces except the GetChangeType which is for convenient. The most important interface is the Execute which will be called when subscribed events happen (here is the parameter value changed event). We can also subscribe Application.DocumentChanged but this event will be triggered for any change in the document. So we would strongly suggest to use IUpdater mechanism for this case.
Then in your own OnStartup interface function add following code:
ParameterUpdater updater = new ParameterUpdater(uiControlledApplication.ActiveAddInId, BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))
UpdaterRegistry.RegisterUpdater(updater);
ElementCategoryFilter pipeFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves);
ElementIsElementTypeFilter nonTypeFilter = new ElementIsElementTypeFilter(true);
LogicalAndFilter filter = new LogicalAndFilter(pipeFilter, nonTypeFilter);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, updater.GetChangeType());
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementAddition());
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementDeletion());
Here we subscribed the Comments parameter which you can change to any parameter you want. Another thing I want to mention is that ParameterUpdater won’t be triggered when new element is added or element is deleted, so we also registered Element.GetChangeTypeElementAddition() and Element.GetChangeTypeElementDeletion() to track new element and element deletion.