We have talked about implementing a sample ITransactionFinalizer interface previously. In this post, let’s see how Transaction Finalizer of RevitAddinWizard can assist us to do the same work.
Transaction Finalizer can be found from the Revit Addin category of the Project Items window:
Its welcome page looks like:
Input the Transaction Finalizer class name and choose whether to add default messages to its method implementations or not:
Input the name of the associated transaction and choose an external command:
In the summary page, we can review whether all settings are as expected. If not we still have a chance to go back to previous pages and change them.
After the Finish button is pressed, a Transaction Finalizer will be created as follows:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS4
{
public class TransactionFinalizer1 : ITransactionFinalizer
{
#region ITransactionFinalizer Members
public void OnCommitted(Document document, string strTransactionName)
{
string msg = string.Format("Transaction {0} on document {1} has been committed.", strTransactionName, document.Title);
TaskDialog.Show(this.ToString(), msg);
}
public void OnRolledBack(Document document, string strTransactionName)
{
string msg = string.Format("Transaction {0} on document {1} has been rolled back.", strTransactionName, document.Title);
TaskDialog.Show(this.ToString(), msg);
}
#endregion
}
}
In addition, a help method will also be added to the chosen external command class:
public static void TransactionWithFinalizer(RvtDocument doc)
{
Transaction trans = new Transaction(doc, "TransactionWithFinalizer");
FailureHandlingOptions fhOpts = trans.GetFailureHandlingOptions();
fhOpts.SetTransactionFinalizer(new TransactionFinalizer1());
trans.Start();
try
{
// Do something with the trans.
trans.Commit(fhOpts);
}
catch
{
trans.RollBack(fhOpts);
}
}
Give Transaction Finalizer of RevitAddinWizard a try and you will get all these in no time.
Recent Comments