Start Method


Transaction Start Method

Starts the transaction.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public TransactionStatus Start()

Return Value

TransactionStatus
If finished successfully, this method returns TransactionStatus.Started. Note that unless starting is successful, changes cannot be made to the document.
Exceptions
Exception Condition
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.
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.

Example
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);
           }
       }
    }
}
See Also