Start transaction not working with Revit 2014

Start transaction not working with Revit 2014

pfk
Enthusiast Enthusiast
4,324 Views
7 Replies
Message 1 of 8

Start transaction not working with Revit 2014

pfk
Enthusiast
Enthusiast

Hi

 

I have a plugin which works fine with Revit 2012 and 2013.  On Revit 2014, the call to Transaction.Start throws an exception "Starting a transaction from an external application running outside of API context is not allowed.".  Has something changed between Revit 2013 and 2014 that does not allows transactions from plugin?

 

Thanks

0 Likes
Accepted solutions (2)
4,325 Views
7 Replies
Replies (7)
Message 2 of 8

ollikat
Collaborator
Collaborator
Accepted solution

Hi

 

Maybe it's related to this comment in "What's new" section in 2014 API documentation:

No transactions from outside threads

Calling into the Revit API from outside threads and outside modeless dialogs has never been supported, but it was not strictly prohibited, meaning there would be no immediate exceptions when someone tries to modify model from outside of the supported API workflows. That has been changed. It is no longer possible to start a transaction unless the caller is inside a legitimate API call, such as an external command, event, updater, call-back, etc. An exception will be thrown if such attempt is made

0 Likes
Message 3 of 8

pfk
Enthusiast
Enthusiast
Accepted solution

Yes - that would appear to be the issue.

 

Given this new restriction, I do not understand how you could open a transaction whilst a 3d perspective window is open, because the idler event does not get sent when in these views, nor are external commands available.  So many plugins which use the 3d perspective view will simply not work anymore.

 

Paul

0 Likes
Message 4 of 8

arnostlobel
Alumni
Alumni

It is not a new restriction per se. Calling from an outside thread (including external modeless dialogs) has never been supported in Revit unless the API calls are made from a handler of an Idling event (since 2012) or External Event (since 2013). Both approaches are well documented in SDK samples – Look for ModelessDialog in the Samples Folder. External Events are particularly useful in modeless dialogs. They allow a clean, safe, and easy workflow.

 

However, you are correct about calling the API while the active view is Perspective. That has never been allowed, and, in fact, most Revit internal commands are disabled in that mode too. There is a task open for enabling the API in Perspective and we hope to make it happen as soon as we figure out a reasonably safe way. It is not as trivial as it may sound. I am sorry for that.

 

Arnošt Löbel

Autodesk Revit R&D

Arnošt Löbel
0 Likes
Message 5 of 8

pfk
Enthusiast
Enthusiast

Thanks Arnošt

 

I appreciate the detailed reply, and understand the situation.  In general I think users do not want to loose functionality when going to the next release of a product, so perhaps this restriction could have be bought in AFTER the API had been enabled in the Perspective view.

 

Paul

0 Likes
Message 6 of 8

arnostlobel
Alumni
Alumni

Hello Paul,

 

While I understand your frustration over the limitation, we did not really have a choice. Like I said, the workflow was never supported nor recommended. It was a bit of an oversight on our side not to put in the restriction a few releases earlier, even though we have always documented and advocated the correct approach. Over the last few years we have found too many a document corrupted and Revit session abruptly terminated, and in most if not all of such cases our investigation lead us to external addins accessing the API when they were not supposed to do so. Such attempts are always risky and down plain dangerous when outside transactions are started. While we understand that our decision might frustrate a few developers, we honestly believe it was a decision for the better and that most end-users will benefit from it rather than suffer.

 

Thank you for your understanding

 

Arnošt Löbel

Autodesk Revit R&D

Arnošt Löbel
0 Likes
Message 7 of 8

Anonymous
Not applicable

So how do we fix this problem?  I have the same issue

0 Likes
Message 8 of 8

arnostlobel
Alumni
Alumni
I am afraid you cannot. Since the Revit API cannot be used in a perspective views (it never been able to, and it is documented), and since the API cannot be invoked outside of the main thread in Revit (has always been this limited, and it is documented), the scenarios mentioned above are not technically supported. We have may be able to allow the API in perspective views in the future; unfortunately it is not as simple as turning On a flag somewhere, so I cannot give any time estimates.

Thank you

Arnošt Löbel
Autodesk Revit R&D
Arnošt Löbel
0 Likes