Naming Dynamo transactions in Revit

When running Dynamo scripts in Revit we do get a chance to undo which is all well and good however the name for the transaction isn’t meaningful at all.

Is there any way to change the name of these transactions as in the Revit API Transaction.Start("Transaction Name") so users have a better idea what script they are undoing?

Cheers.

3 Likes

@HossZamani You can still use

from Autodesk.Revit.DB import Transaction
t = Transaction(doc, 'Name')
t.Start()
#Do stuff
t.Commit() 

but look at this post:

1 Like

This is possible but only within one Python node. If you have multiple Python nodes which do different changes to the database and you put the code in each node within one transaction, you get multiple undo commands for one single Dynamo run.

What I’m looking to do is to group all these transactions and have whatever done in one script run as a single undo command with the given name. There’s a class in Revit API called TransactionGroup but not sure how to use it in this context (multiple Python nodes) to achieve the above.

Does it make sense?

I can’t say I have seen this - can you share a sample dyn that illustrates the bahavior?

TransactionUndoTest.dyn (16.1 KB)

Here is a quick test. Running this will result in two undo commands.

Untitled

1 Like

Hi @HossZamani

You can use TransactionGroup this way:

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
from Revit.Elements import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

p1 = IN[0].ToXyz()
p2 = IN[1].ToXyz()
level = UnwrapElement(IN[2])
fam = UnwrapElement(IN[3])


tGroup = TransactionGroup(doc, 'Place Families')
tGroup.Start()
trans1 = Transaction(doc, 'Place Family1')
trans1.Start()
instance1 = doc.Create.NewFamilyInstance(p1, fam, level, Structure.StructuralType.NonStructural)
trans1.Commit()
trans2 = Transaction(doc, 'Place Family2')
trans2.Start()
instance2 = doc.Create.NewFamilyInstance(p2, fam, level, Structure.StructuralType.NonStructural)
trans2.Commit()
tGroup.Commit()

OUT = instance1,instance2

And here is the process in action:

9 Likes

Thanks @Kulkul. Yeah I was aware of that. Essentially what you are doing is grouping the transactions of a single Python node. That’s possible. What I was looking for was to group every transaction of a Dynamo run in a single transaction. A dyn file could have multiple Python nodes and inside each they can have transactions plus many other nodes which change the Revit database and therefore have their own transactions.

@HossZamani Is this what your looking for?

Sorry, it seems I’m not explaining the issue clearly. What I’m looking for is quite the opposite. Essentially what I want is one single undo command with a meaningful name for whatever that has been done in a Dynamo run…

As mentioned above this Dynamo run may include several Python nodes in which they have several transactions and/or several other nodes that have their own transaction.

Does it make more sense?

@HossZamani Yes it does now. Sorry i thought you want to undo one by one. So you want to combine multiple transactions into one undo?

Correct, but these transactions may be in multiple Python nodes and/or transactions of other non-Python nodes.

@HossZamani Have a look at this discussion:

https://forums.autodesk.com/t5/revit-api-forum/combine-multiple-transactions-into-one-undo/m-p/5502149/

Hmm… Thanks. That’s also using TransactionGroup class which is possible only within one Python node. By the look of it grouping all transaction in a dyn file isn’t possible or at least we have to dive deeper than that.

I suspect there might be a way using Dynamo API but have to investigate. I’ll post here if I find something.

Hi @HossZamani ,
It’s been few years since your question, but I am interested in knowing the same:
How to have a one undo command for whatever was done in a single Dynamo run.

Has this been solved in the mean time?
Or is it still not possible to be done in Dynamo?
I appreciate your answer on this.

This is the default behavior. If you are utilizing custom transactions, than you’d wind up with multiple items in the undo stack.

1 Like