#RTCEUR Wish #1: #Revit Change Tracking

Dieter asked “What about a tool that can help you tracking changes in your #Revit model. E.g. select elements that were affected by an indicated change. Eg after updating model from RSA. Maybe a dialog showing the history”

If you want to log every change made to your Revit model and what elements are affected by that change, the DocumentChanged event is what you need.

The code below outputs the time, user name, transaction name, and all added, modified, and deleted elements for each transaction.

For simple annotation operations, the output is relatively straightforward:

10/30/2014 3:58:43 PM,harry_000,Edit Text,ADDED,1074184(Text Notes: 2.5mm Arial),,DELETED,,MODIFIED,
10/30/2014 3:58:54 PM,harry_000,Add Left Arc Leader,ADDED,,DELETED,,MODIFIED,1074184(Text Notes: 2.5mm Arial),
10/30/2014 3:59:02 PM,harry_000,Detail Lines,ADDED,1074193(Lines: Detail Lines),,DELETED,,MODIFIED,
10/30/2014 3:59:11 PM,harry_000,Place Dimensions,ADDED,1074208(Dimensions: Feet & Inches),,DELETED,,MODIFIED,

For other transactions (such as creating a column or moving a grid), the output shows that Revit is making a whole lot of changes.

10/30/2014 4:01:05 PM,harry_000,Structural Column,ADDED,1074223(Structural Columns: L127X127X9.5),1074224(Analytical Columns),1074245(Analytical Nodes),1074246(Analytical Nodes),1074247(Analytical Nodes),1074248(Analytical Nodes),,DELETED,,MODIFIED,102467(AutoJoin Tracker Element),102521(Element to track Analytical Sets during regeneration),103632(GCS Tracker),132466(Hubs Tracker),

10/30/2014 4:01:54 PM,harry_000,Nudge Right,ADDED,,DELETED,,MODIFIED,9745(System Data),86962(System Data),102467(AutoJoin Tracker Element),103632(GCS Tracker),132466(Hubs Tracker),195239(Grids: 2),414482(Structural Columns: M_1000),414483(Analytical Columns),414562(Analytical Nodes),414564(Analytical Nodes),428588(Walls: SIP 202mm Wall – conc clad),428745(Walls: SIP 202mm Wall – conc clad),457479(Windows: Standard),485432(Windows: Standard),554066(Constraints: Alignment),554069(Constraints: Alignment),670283(Dimensions: Feet & Inches),760918(M_1000),857235(<Area Boundary>: Model Lines),857236(<Area Boundary>: Model Lines),857239(),940871(Window Tags: M_Window Tag),940919(Window Tags: M_Window Tag),941385(Dimensions: Feet & Inches),

For a real application you might want to write this data to a database instead of a text file, and build a viewer to get more info about the added and modified elements based on their element ids.

void ControlledApplication_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
    string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CommandLogging.csv");
    using (StreamWriter sw = new StreamWriter(file, true))
        foreach (string transactionName in e.GetTransactionNames())
            sw.Write(DateTime.Now + "," + Utils.username + "," + transactionName);
            sw.Write(",ADDED," + idCollectionToString(e.GetDocument(), e.GetAddedElementIds()));
            sw.Write(",DELETED," + idCollectionToString(e.GetDocument(), e.GetDeletedElementIds()));
            sw.Write(",MODIFIED," + idCollectionToString(e.GetDocument(), e.GetModifiedElementIds()));

private string idCollectionToString(Document doc, ICollection<ElementId> coll)
    string ret = "";
    foreach (ElementId id in coll)
        Element e = doc.GetElement(id);
        string name = "";
        if (e != null)
            string catName = "";
            if (e.Category != null)
                catName = e.Category.Name;
            if (e.Name != "" && catName != "")
                catName += ": ";
            name = "(" + catName + e.Name + ")";
        ret += id.IntegerValue.ToString() + name + ",";
    return ret;

2 thoughts on “#RTCEUR Wish #1: #Revit Change Tracking

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 )

Google photo

You are commenting using your Google 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