I wonder that what’s the problem of my code, anyonre can give a help??
Actually, I did once transaction before, however, I dont know why I cannot do it again
The error is like the figure below
In this project, I am dealing with generating slanted columns by using Revit API
Last part of my code about transaction as picture below.
trans = DB.Transaction(doc)
trans.Start()
nested_list_columns = []
for list_line, list_column, list_level in zip(corresponding_line, corresponding_col_element, corresponding_level_element):
temp = []
for line, column, level in zip(list_line, list_column, list_level):
temp.append(doc.Create.NewFamilyInstance(line,column,level, STR.StructuralType.Column))
nested_list_columns.append(temp)
trans.Commit()
The input data of Create.NewFamilyInstance method are three nested list data, and I am sure that the data are definitely correct like the picture.
Why don’t you use the Transaction Manager? This class is designed to overcome this kind of troubles
There is also a method called ForceCloseTransactions
Import the Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#your Code Goes here
#End Transaction
TransactionManager.Instance.TransactionTaskDone()
I would also be good to use the “with” statement in Python:
with Transaction(doc,"SomeTranseAction") as transaction:
transaction.Start()
#Your Code Goes Here
transaction.Commit()
The “with” statement makes sure to dispose (throw away) the Transaction Object after you are done with it.
3 Likes
You are committing a transaction in a loop. Try to commit it with same level as trans.Start()
3 Likes
@Joelmick Thank you for your answer immediately
By using the Transaction Manager, it works, also, the way you mentioned, “with” that it works!
but the scale of objects would be not what I want, which is bigger than what I expected, I think I should translate the scale due to feet and cetimeter?
The ForceCloseTransaction method I wil try out later, I can find out on the website RevitAPIdocs
Anyway, Thank you very mcuh!
#TransactionManager.Instance.EnsureInTransaction(doc)
with DB.Transaction(doc, 'SomeTransAction') as trans:
trans.Start()
nested_list_columns = []
for list_line, list_column, list_level in zip(corresponding_line, corresponding_col_element, corresponding_level_element):
temp = []
for line, column, level in zip(list_line, list_column, list_level):
temp.append(doc.Create.NewFamilyInstance(line,column,level, DB.Structure.StructuralType.Column))
nested_list_columns.append(temp)
trans.Commit()
#TransactionManager.Instance.TransactionTaskDone()
Thank you so much, I got a mistake when I paste the code, still, appreciate your advise!
if you want to use Revit Transaction instead of Dynamo transaction, you need to close before dynamo transaction group with
TransactionManager.Instance.ForceCloseTransaction()
then
trans = DB.Transaction(doc)
trans.Start('MyTransaction')
#
#
#
trans.Commit()
1 Like
So for scaling (FamilyInstances do not appear on the correct position) you should create another topic.
But Dynamo Offers Converions Methodes for Dynamo Geometry to Revit Geometry
These will transform the geometry by whatever units your are using in your model to feet.