SetName Method


Sets the transaction's name.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)

Syntax

C#
public void SetName(
	string name
)
Visual Basic
Public Sub SetName ( _
	name As String _
)
Visual C++
public:
void SetName(
	String^ name
)

Parameters

name
Type: System String
A name for the transaction.

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.

Examples

Copy C#
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;
}
Copy VB.NET
Public Function ModelChangingMethod(document As Autodesk.Revit.DB.Document) As Boolean
    Dim result As Boolean = 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 As 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 Then
            ' 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() Then
                result = False
            End If
        Else
            ' if modifications failed, transaction is to be rolled back
            transaction.RollBack()
        End If
    End Using
    Return result
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException The name argument is an empty string.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL

See Also