Start Method


Starts the transaction.

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

Syntax

C#
public TransactionStatus Start()
Visual Basic
Public Function Start As TransactionStatus
Visual C++
public:
TransactionStatus Start()

Return Value

If finished successfully, this method returns TransactionStatus.Started. Note that unless starting is successful, changes cannot be made to the document.

Remarks

A transaction may be started only after it was instantiated or after it was previously committed or rolled back. In order to start a transaction, it must have a name assigned. If the name was not specified when the transaction object was instantiated, it has to be set by calling the SetName(String) method.

Be aware that every time a transaction starts, Failure Handling Options will be reset to their default values. If a specific failure handling is required, programmers need to use SetFailureHandlingOptions(FailureHandlingOptions) before the transaction is committed or rolled back.

Examples

Copy C#
public void TransactionDuringElementCreation(UIApplication uiApplication, Level level)
{
    Autodesk.Revit.DB.Document document = uiApplication.ActiveUIDocument.Document;

    // Build a location line for the wall creation
    XYZ start = new XYZ(0, 0, 0);
    XYZ end = new XYZ(10, 10, 0);
    Autodesk.Revit.DB.Line geomLine = Line.CreateBound(start, end);

    // 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 wallTransaction = new Transaction(document, "Creating wall"))
    {
       // To create a wall, a transaction must be first started
       if (wallTransaction.Start() == TransactionStatus.Started)
       {
           // Create a wall using the location line
           Wall wall = Wall.Create(document, geomLine, level.Id, true);

           // the transaction must be committed before you can
           // get the value of Geometry and AnalyticalModel.

           if (wallTransaction.Commit() == TransactionStatus.Committed)
           {
               Autodesk.Revit.DB.Options options = uiApplication.Application.Create.NewGeometryOptions();
               Autodesk.Revit.DB.GeometryElement geoelem = wall.get_Geometry(options);
               Autodesk.Revit.DB.Structure.AnalyticalModel analyticalmodel = wall.GetAnalyticalModel();
           }
       }
    }
}
Copy VB.NET
Public Sub TransactionDuringElementCreation(uiApplication As UIApplication, level As Level)
    Dim document As Autodesk.Revit.DB.Document = uiApplication.ActiveUIDocument.Document

    ' Build a location line for the wall creation
    Dim start As New XYZ(0, 0, 0)
    Dim [end] As New XYZ(10, 10, 0)
    Dim geomLine As Autodesk.Revit.DB.Line = Line.CreateBound(start, [end])

    ' 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 wallTransaction As New Transaction(document, "Creating wall")
        ' To create a wall, a transaction must be first started
        If wallTransaction.Start() = TransactionStatus.Started Then
            ' Create a wall using the location line
            Dim wall__1 As Wall = Wall.Create(document, geomLine, level.Id, True)

            ' the transaction must be committed before you can
            ' get the value of Geometry and AnalyticalModel.


            If wallTransaction.Commit() = TransactionStatus.Committed Then
                Dim options As Autodesk.Revit.DB.Options = uiApplication.Application.Create.NewGeometryOptions()
                Dim geoelem As Autodesk.Revit.DB.GeometryElement = wall__1.Geometry(options)
                Dim analyticalmodel As Autodesk.Revit.DB.Structure.AnalyticalModel = wall__1.GetAnalyticalModel()
            End If
        End If
    End Using
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions InvalidOperationException Cannot modify the document for either a read-only external command is being executed, or changes to the document are temporarily disabled. -or- The transaction's document is currently in failure mode. No transaction operations are permitted until failure handling is finished. -or- The transaction started already and has not been completed yet. -or- Starting a new transaction is not permitted. It could be because another transaction already started and has not been completed yet, or the document is in a state in which it cannot start a new transaction (e.g. during failure handling or a read-only mode, which could be either permanent or temporary). -or- The transaction does not have a valid name assigned yet.

See Also