Why do we need Transaction.Start and End nodes

Why do we need Transaction.Start and End nodes in Dynamo when Revit API do it automatically?
Does it help when process get error? Sometimes I got error in Dynamo process and could not undo the result in Revit so I wonder if Transaction node can solve this situation.
Thanks!

@Jin ,

I had here a similar issue… i wanted that transaction done by element instead of list-tasks…

i can`t not answer your question directly

1 Like

Some tasks cannot be completed in one go as Revit needs to commit a change in the first part of the graph before it can start the second part of the graph, as otherwise properties of an object wouldn’t be readable as the object doesn’t exist yet.

A hypothetical example of this is creating a view and then getting all elements in the view. Revit hasn’t yet drawn the view, so identifying what we can see isn’t doable just yet.

The way to do this is usually with a Transaction.End and then a Transaction.Start node directly after each other. Python can also work.

Generally speaking it’s best to keep things to a single transaction as it reduces runtime and keeps the undo menu from becoming polluted.

6 Likes

Transaction will help you manage well, that, you can easily complete the actions inside a transaction. To be able to understand the transaction, the main essence is to perform a job that changes the database: Add, delete, modify, … the implementation of transactions helps ensure integrity and processing Database error.

In Dynamo Revit, you can Start and Commit a transaction with :

import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Do some action in a Transaction
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
#Do Action Add, Modify , Delete,...
TransactionManager.Instance.TransactionTaskDone()

Or inside Revit API

 using (Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(_doc,"do"))
        {
            tran.Start();
//DO Action
            tran.Commit();
        }

Or in SQL

   SqlCommand command = connection.CreateCommand();
        SqlTransaction transaction;

        // Start a local transaction.
        transaction = connection.BeginTransaction();
// DO Action

To understand all the transactions inside Dynamo Revit, you can learn more about : SubTransaction, Transaction, TransactionGroup.

Rollback is method help you undo an action before in case error, let use try except to catch with Python or try catch with C#

4 Likes

I understand that it keeps process work in order instead of being parallel. Could you give an example image for how to use them in Dynamo graph?
And One more thing, does Transaction take any role to make Revit can be undo to previous situation (before the tool action) Or Dynamo has already done that automatically?
Thank you!

1 Like

For examples of how to use them, there are a few examples you can find on the forum by searching for “add a transaction.end” on the forum. Here is one such example:

For the impact on the Revit graph, best to check yourself as I don’t have access to anything but my iPad this week (on vacation) so I can’t launch Revit to confirm.

2 Likes