Starts the transaction.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Syntax
Return Value
If finished successfully, this method returns TransactionStatus.Started.
Note that unless starting is successful, changes cannot be made to the document.
Remarks
Examples
CopyC#
public void TransactionDuringElementCreation(UIApplication uiApplication, Level level)
{
Autodesk.Revit.DB.Document document = uiApplication.ActiveUIDocument.Document;
XYZ start = new XYZ(0, 0, 0);
XYZ end = new XYZ(10, 10, 0);
Autodesk.Revit.DB.Line geomLine = Line.CreateBound(start, end);
using (Transaction wallTransaction = new Transaction(document, "Creating wall"))
{
if (wallTransaction.Start() == TransactionStatus.Started)
{
Wall wall = Wall.Create(document, geomLine, level.Id, true);
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();
}
}
}
}
CopyVB.NET
Public Sub TransactionDuringElementCreation(uiApplication As UIApplication, level As Level)
Dim document As Autodesk.Revit.DB.Document = uiApplication.ActiveUIDocument.Document
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])
Using wallTransaction As New Transaction(document, "Creating wall")
If wallTransaction.Start() = TransactionStatus.Started Then
Dim wall__1 As Wall = Wall.Create(document, geomLine, level.Id, True)
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