Reputation: 1532
I'm working on a button where I have a project document open and a family document open. I'm trying to close the family document however I'm getting an error saying:
Autodesk.Revit.Exceptions.InvalidOperationException: 'Close is not allowed when there is any open sub-transaction, transaction, or transaction group.'
I've checked all of my transactions and they are all started and committed using transactionName.Start(document)
and transactionName.Commit()
does anyone know of a way to check for any ongoing active transactions?
I have also tried using
'RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId(PostableCommand.Close);
uiapp.PostCommand(closeDoc);'
however that tends to only want to close my project document.
///////////////////////////////////UPDATE///////////////////////////// soooo I just found out I didn't need to use uiapp.OpenAndActivateDocument(). I didn't know you could edit a family without opening the document. That solves my problem. I'm still curious if there's a way to check for open transactions though.
Upvotes: 1
Views: 4229
Reputation: 588
Yes there is a way to check for open Transactions and its quite helpful in making flexible helper-functions. The Document
object has an IsModifiable
property - essentially if a Transaction is open, then this will be True.
I use it like this:
autoTransaction = False
if not document.IsModifiable:
t = Transaction(document, 'New Transaction cause no transaction was open')
t.Start()
autoTransaction = True
# go ahead and modify the database
if autoTransaction:
t.Commit()
Its served me well so far, hope this helps!
Upvotes: 2
Reputation: 8294
Afaik, the Revit API does not enable you to check from outside whether a transaction is started. You need access to the Transaction
object itself to check its status. If you did not create it yourself, you have no access to it.
How did you open the two documents?
What Revit commands did you execute in them?
Upvotes: 1