I'm working with a DocumentChanged event in the ExternalApplication class. I cannot figure out how to get the document that is passed to my DocumentChanged event to be modifiable. Is it possible?
My DocumentChanged event works fine when I trigger it from an IExternalCommand, so I think the main issue is the non-modifiable document passed from the External App. Any help is appreciated!
Solved! Go to Solution.
Actually, the document for which a DocumentChanged event is raised is never modifiable. Other documents (if there are other documents currently open) may be modifiable depending on their respective state, but the actual document in which the change was just made is always set to be read-only for the entire duration of the DocumentChanged event. This is completely intentional. The are several reasons, in fact. For one, if the change was a result of a completed transaction, the transaction has already been finalized and would not accept any other changes. That is the most common case of all. Or, if the event was raised as a result of undoing or redoing of transactions, the document is out of a transaction at that moment and therefore immutable. Furthermore, since creating new transactions while undoing or redoing cannot be allowed, the document must be set read-only.
As a general rule, the DocumentChanged was not designed for the scenarios in which a document gets modified as a result of some other changes happening in that very same document. In such scenarios, the Dynamic Updaters are the right tool to be utilized.
By the way, you cannot trigger the event from your External Command. Only Revit can trigger it, since the Revit Application is the event’s originator and sender. You can invoke your handler for that event, but that is not the same. When you invoke the handler explicitly, the document will have the state you are currently in, therefore it is perfectly expectable it would be modifiable if you are invoking it from an external command and you happen being in in a transaction at that moment (either automatic or manual).
Autodesk Revit R&D
This is great! Thank you, Arnošt.
I hadn't yet discovered the Dynamic Updaters, but after reading your post I looked them up, and it seems to be what I need instead of the DocumentChanged event.
For anyone else looking for this info, it's under IUpdater in the API, and here:
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register