#RTCNA wish almost granted – clear keynote when duplicating types

Clearing out my RTC API Wishlist Inbox… (do you have more wishes? RTCEUR is coming in 3 months)

Nicklas asks

Is it possible to create a macro that resets keynote when a family is duplicated?

The code and video below shows how Dynamic Model Update can be used to clear the Keynote parameter’s value any time a new Element Type is added to the file. But the problem with this is that it does not distinguish the different ways that a new Element Type can be added.

You can duplicate a type (the scenario that Nicklas wants to capture) but it also triggers when you load a family (a scenario that probably should not clear the keynote values for the just loaded families). The solution to this might include subscribing to the DocumentChanged event and using the GetTransactionNames Method to differentiate between a Duplicate and Load Family.

public void addTrigger()
    Application app = this.Application;
    MyUpdater udpater = new MyUpdater(app.ActiveAddInId);
    UpdaterRegistry.RegisterUpdater(udpater, true);
                               new ElementClassFilter(typeof(ElementType)), 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("FB1BA6B2-4C06-42d4-97C1-D1B4EB593EFA"));
    public void Execute(UpdaterData data)
        Document doc = data.GetDocument();
            foreach (ElementId id in data.GetAddedElementIds())
                ElementType etype = doc.GetElement(id) as ElementType;
                if (etype == null)
                Parameter p = etype.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);
                if (p == null)
        catch (Exception ex)
            string s = ex.Message;
            TaskDialog td = new TaskDialog("MyUpdater Exception");
            td.MainInstruction = ex.Message;
            td.MainContent = ex.StackTrace;
    public string GetAdditionalInformation() { return ""; }
    public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; }
    public UpdaterId GetUpdaterId() { return m_updaterId; }
    public string GetUpdaterName() { return "MyUpdater"; }

5 thoughts on “#RTCNA wish almost granted – clear keynote when duplicating types

  1. Hi

    This blog is so nice, you have opened a hole new world in revit for me. Thank you.

    Revit macro are new for me and i tried to use this one but i keep getting erros.
    cs0118 is a ‘namespace’ but is used like a ‘type’

    I am i doing a rookie mistake?

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 )

Connecting to %s