mitevpi / revit-wpf-template

Template for a Revit add-in using WPF and executing valid external commands within the Revit API context.
https://revit-wpf-template-docs.now.sh
MIT License
160 stars 43 forks source link

Transactions Impossible? #9

Open RyanDaley opened 1 year ago

RyanDaley commented 1 year ago

I am writing new methods in the Methods.cs class. Everything works fine until I try to use a transaction to make a change to the active document. I can't get transactions to work at all. Are transactions not possible from a plugin?

RyanDaley commented 1 year ago

image

mitevpi commented 1 year ago

Transactions are possible from a plugin, but they have to happen in a valid Revit API context.

Here is an example method using a transaction in this template

And here is how that same method is invoked from the WPF UI.

Most of the work is done by the RevitEventWrapper which basically just ensures the transaction happens in a "valid Revit API context".