Transaction Error when executing as an application

Transaction Error when executing as an application

Simon.Pusateri
Contributor Contributor
636 Views
4 Replies
Message 1 of 5

Transaction Error when executing as an application

Simon.Pusateri
Contributor
Contributor

Hello all,

 

I am working to create an add-in for Revit 2021 that copies selected viewports from one sheet to one or more other sheets. When I run my add-in as a command things work fine, but when I run it as an application by clicking a button that I added to my ribbon, I end up getting an error saying that a transaction was opened but not closed.

SimonPusateri_0-1652280068736.png


I'm not sure why I am getting this error because I don't have any transactions in my Application.cs file, only in the Command file, which as I said, worked fine by itself. Any help here would be appreciated!


Simon

0 Likes
Accepted solutions (1)
637 Views
4 Replies
Replies (4)
Message 2 of 5

halukuzuner
Advocate
Advocate

Could you share code? Does your code have form?

Message 3 of 5

Simon.Pusateri
Contributor
Contributor

Here is the source code - sorry in advance for any poor coding, I am still relatively new to C#. CopySheetViews is the Command file and Application is the Application. Copy Sheet views does have a form which allows the user to select from a list of all the sheets in the project. Do you think that could be where the issue is coming from?

 

Thanks in advance,

 

Simon

0 Likes
Message 4 of 5

kraftwerk15
Advocate
Advocate
Accepted solution

In your CopySheetViews class, best practice would be to Show the Dialog to the user, get some data from the Dialog after they have modified the data you want them to, and then having a method (either here or in another class) where you modify the Revit database.

 

I would not lump all user interactions under a transaction as it can lead to issues. Remember that "Getting" data from the database does not require a transaction, but "Setting" data to the database does. Keep the Transaction simple, quick, easy, and then closing the Transaction will make debugging this a lot easier.

0 Likes
Message 5 of 5

Simon.Pusateri
Contributor
Contributor

You nailed it! I moved the start of the transaction after the form and it worked. Thanks for your help!

0 Likes