clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import sys
pyt_path=r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0],list):
category = UnwrapElement(IN[0])
else:
category = [UnwrapElement(IN[0])]
if isinstance(IN[1], list):
views = UnwrapElement(IN[1])
else:
views = [UnwrapElement(IN[1])]
if isinstance(IN[2],list):
bools = IN[2]
else:
bools = [IN[2]]
docs = IN[3]
report = []
outDocuments = []
for view,famDoc in zip(views,docs):
TransactionManager.Instance.EnsureInTransaction(famDoc)
for cat,bool in zip(category,bools):
try:
view.SetCategoryHidden(cat.Id,bool)
outDocuments.append(famDoc)
rep = famDoc
except:
import traceback
rep = traceback.format_exc()
outDocuments.append(famDoc)
TransactionManager.Instance.TransactionTaskDone()
report.append(rep)
OUT = outDocuments,report
The first transaction works fine, but the next one gets the error that the transaction is outside of a transaction. In my opinion, I close the transaction in every loop. Isn´t it possible to start and end transactions this way?
I also attached the Dynamo File. Im my folder there are three random families. _multiple_transactions.dyn (30.7 KB)
At a quick glance the “report.append(rep)” is probably in the wrong spot. It’s trying to work in the outer loop not the inner loop where you probably want it. Try this at the end and let me know if it works.