Transactions in Python

I’m struggling to understand how transactions work in python in RhinoInside.Revit.

Using the TransactionManager gives me and “outside of API context” error.

I tried using trans.Start() and trans.Commit(), but that seemed a little unstable and caused weird things to happen in my project browser.

And I have used EnqueueAction with success, but I don’t understand how it works. And inside this Action I don’t get any errors if something isn’t working, so if it doesn’t do what i want it to do, i usually have to resort to adding one line at a time and constantly rerunning until I find my error.

But all of this is to try to understand how I might use EditFamily in my script to add geometry to a family and reload it into the project. In the past, I used TransactionManager with a new transaction for the familyManager, but TransactionManager doesn’t seem to be the way to go with RiR.

Any help with understanding transactions in RiR context and with how to get them to work with the EditFamily and FamilyManager would be super helpful. Thanks!

1 Like

Seconded - it would be great to understand in more detail how to use the TransactionManager in RiR. I’m not sure what is going on with EnqueueAction…

Tacking on some other questions I have about transactions:

Revit.EnqueueAction seems to fail when calling def function from within the EnqueueAction. For example, I have portion of code that adds a bitmap to a material. It works fine if the code is written in the EA function. If i place it in its own function and call to it from within the EA function, it fails, even though the code is exactly the same. (Edited because I made dumb mistakes)

Also, small issue: How do I regenerate the Revit model from the python script? I can’t call doc.Regenerate() outside of the EnqueueAction function because then it is outside of a transaction, but if I call it inside of the function the Revit model doesn’t regenerate because it is technically part of that very transaction afterwhich i need to regenerate.

Also, is there a way to determine if the EnqueueAction is successful without looking to see if the changes were made or looking at the undo stack for a RhinoInside event? as I pointed out in the first post, no errors are displayed if the action fails.

Really enjoying Rhino Inside and have already developed a lot of helpful tools. Gamechanger! Just looking to understand some of this transaction business a little better.