“View” Field added to a Detail Item Schedule

Revit 2014 can schedule detail items, but some people still aren’t satisfied because out-of-the-box Revit doesn’t schedule the detail item’s view. Here’s an API solution for that.

// typically this would be done during OnStartup		
public void registerUpdater()
{
    MyUpdater updater = new MyUpdater(this.Application.ActiveAddInId);
    UpdaterRegistry.RegisterUpdater(updater);

    LogicalOrFilter orFilter =  new LogicalOrFilter
                               (new ElementClassFilter(typeof(View)),
                                 new ElementClassFilter(typeof(FamilyInstance)));

    UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), orFilter, Element.GetChangeTypeAny());
    UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), orFilter, Element.GetChangeTypeElementAddition());
}

public class MyUpdater : IUpdater
{
    static AddInId m_appId;
    static UpdaterId m_updaterId;
    public MyUpdater(AddInId id)
    {
        m_appId = id;
        m_updaterId = new UpdaterId(m_appId, new Guid("F2FBF6B2-4C06-42d4-97C1-D1B4EB593EFF"));
    }
    public void Execute(UpdaterData data)
    {
        Document doc = data.GetDocument();
        foreach (Element e in new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_DetailComponents))
        {
            Element v = doc.GetElement(e.OwnerViewId);
            e.get_Parameter("View").Set(v.Name);                        
        }
    }
    public string GetAdditionalInformation() { return "Detail View Parameter"; }
    public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; }
    public UpdaterId GetUpdaterId() { return m_updaterId; }
    public string GetUpdaterName() { return "Detail View Parameter"; }
}
Advertisements

3 thoughts on ““View” Field added to a Detail Item Schedule

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s