'Starting a new transaction is not permited'

Does anyone know what could be the problem here :slight_smile:

image

It’s a really simple script, trying to set limits to all rooms in the project:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
t = Transaction(doc, 'Set room limits')

t.Start()
for room in UnwrapElement(IN[0]):
	levelId = room.LevelId
	room.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET).Set(5)
	room.get_Parameter(BuiltInParameter.ROOM_UPPER_LEVEL).Set(levelId)
t.Commit()

Just found out actually… It works fine on the first run and then it shows this error. When I change the upper limit value though, it works again. Maybe when you open a transaction, but do not assign any new values to the elements’ parameters, it throws this error, does that make sense?

Maybe worth taking a look at this page of the Dynamo Python Primer.

But, to answer your question, if I recall correctly Dynamo has a transaction open by default. So if you want to use the API transaction methods, instead of Dynamo’s transaction as used in the link above, you should close Dynamo’s transaction with TransactionManager.Instance.ForceCloseTransaction() and then open your own.

So:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

TransactionManager.Instance.ForceCloseTransaction()

doc = DocumentManager.Instance.CurrentDBDocument
t = Transaction(doc, 'Set room limits')

t.Start()
for room in UnwrapElement(IN[0]):
	levelId = room.LevelId
	room.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET).Set(5)
	room.get_Parameter(BuiltInParameter.ROOM_UPPER_LEVEL).Set(levelId)
t.Commit()

I believe should fix your problem.

2 Likes

thx! It fixed it. Just had to also import TransactionManager and it’s all good

1 Like