Transaction.SetName Method

TransactionSetName 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
)
Public Sub SetName ( 
	name As String
)
public:
void SetName(
	String^ name
)
member SetName : 
        name : string -> unit 

Parameters

name  String
A name for the transaction.
Exceptions
ExceptionCondition
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;
}
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

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also