TransactionStart Method |
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
public TransactionStatus Start()
Public Function Start As TransactionStatus
public: TransactionStatus Start()
member Start : unit -> TransactionStatus
Return Value
TransactionStatusIf finished successfully, this method returns TransactionStatus.Started. Note that unless starting is successful, changes cannot be made to the document.
| 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. |
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.
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); } } } }
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) End If End If End Using End Sub
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.