Capture Comments When Saving to Central

Steve at Revit OpEd noted recently that occasionally he encounters a bigger problem (room warnings during Save To Central) and a smaller problem (comments entered in the Synchronize With Central dialog are lost):

If you are like me you enter a comment each time (using SwC) for tracking and troubleshooting purposes. It is a pain to get a message telling you your SwC didn’t work. It’s worse that what you typed is lost. I finally got slightly smarter. I try to remember to copy the comment text to the clipboard before clicking OK. This way I can just paste it back in if/or when the error pops up.

We can’t use the API to fix the bigger problem (though there may be some API solution to help mitigate it). But we can definitely use the API to make sure that the comments aren’t lost.

If we subscribe to the DocumentSynchronizingWithCentralEvent, we can use the DocumentSynchronizingWithCentralEventArgs.Comments property to get the comments entered in the Synchronize With Central dialog box. Then we can write them to a text file, database, or other location where they will be safe, regardless of Revit’s success or failure to complete the save.

See my previous post on Events for an introduction to the functionality.

public void SynchWithCentralEventRegister()
{
    this.Application.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(mySynchronizingWithCentralEvent);
}        

private void mySynchronizingWithCentralEvent(object sender, DocumentSynchronizingWithCentralEventArgs args)
{
    string comments = args.Comments;
    
        // Use the @ before the filename to avoid errors related to the \ character
    // Alternative is to use \\ instead of \
    string filename = @"C:\Users\HP002\Documents\SynchronizingWithCentral Comments.txt";

    // Create a StreamWriter object to write to a file
    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filename))
    {
        writer.WriteLine(DateTime.Now + " - " + comments);
    }    
    // open the text file
    System.Diagnostics.Process.Start(filename);
}
Advertisements

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