SetName Method


Transaction Set Name Method

Sets the transaction's name.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public void SetName(
	string name
)

Parameters

name String
A name for the transaction.
Exceptions
Exception Condition
ArgumentException The name argument is an empty string.
ArgumentNullException A non-optional argument was null
Remarks
A transaction needs a name before it can be started, i.e. before one of the 'Start' method is invoked for this transaction object. The name will later appear in the Undo menu in Revit after a transaction is successfully committed.

Another ways of setting the name is either during construction or during the Start(String) method.

Example
public bool ModelChangingMethod(Autodesk.Revit.DB.Document document)
{
    bool result = false;

    // All and any transaction should be enclosed in a 'using'
    // block or guarded within a try-catch-finally blocks
    // to guarantee that a transaction does not out-live its scope.
    using (Transaction transaction = new Transaction(document))
    {
        // We can either start a transaction with a name or give
        // it a name later, but we have to name it before we commit.
        transaction.Start();

        // Some modification(s) of the model here, likely resulting in 
        // changes of the 'result' value
        // result = ..... 

        if (result == true)
        {
            // Since the transaction is still unnamed,
            // we have to give it a name now before we commit

            transaction.SetName("Model change");

            // Now we can commit
            if (TransactionStatus.Committed != transaction.Commit())
            {
                result = false;
            }
        }
        else  // if modifications failed, transaction is to be rolled back
        {
            transaction.RollBack();
        }
    }
    return result;
}
See Also