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
171 stars 46 forks source link

Transactions Impossible? #9

Open RyanDaley opened 2 years ago

RyanDaley commented 2 years 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 2 years ago

image

mitevpi commented 2 years 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".